我想将对象字符串化为查询字符串.
例如,
{ hello: '123', goodbye: "789" }
Run Code Online (Sandbox Code Playgroud)
会给我......
hello=123&goodbye=789
Run Code Online (Sandbox Code Playgroud) <select id="hello">
<option data-title="foo" value="1" selected="selected">Abcdefg</option
</select>
Run Code Online (Sandbox Code Playgroud)
为了获得选择的价值,我通常这样做:
$("#hello").val(); // returns 1
Run Code Online (Sandbox Code Playgroud)
但是,如果我想获得数据标题怎么办?
它是这样的,但这个例子看起来有点复杂.
将simplejson导入为json json.dumps(['foo',{'bar':('baz',None,1.0,2)}])
我的字典是:
myfruits = {'fruit':4, 'color':11}
Run Code Online (Sandbox Code Playgroud)
如何将其转换为JSON,然后使用render_to_response将其拍摄到模板?我正在使用Django.
class{
public HashMap<String, String> eachperson;
apple(){
this.eachperson.put("thekey","thevalue");
}
}
Run Code Online (Sandbox Code Playgroud)
(请原谅班级和职能面前的公众/私人.我只是想知道我是否正确地使用哈希地图.)
有关真实代码,请参阅以下内容:
class ParsedDataSet{
public HashMap<String, String> eachperson;
public List<HashMap<String,String>> peoplelist = new ArrayList<HashMap<String,String>>();
}
class ListprofileHandler extends DefaultHandler{
private boolean in_results = true;
private boolean in_item = false;
private boolean in_first_name = false;
private boolean in_last_name = false;
private boolean in_picture_url = false;
private boolean in_enditem_dummy = false;
private ParsedDataSet dset = new ParsedDataSet();
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if(localName.equals("results")){
this.in_results = …
Run Code Online (Sandbox Code Playgroud) urlReq = urllib2.Request(theurl)
urlReq.add_header('User-Agent',random.choice(agents))
urlResponse = urllib2.urlopen(urlReq)
htmlSource = urlResponse.read()
Run Code Online (Sandbox Code Playgroud)
如何在一行中创建htmlSource,而不是多行?