Cannot iterate the HashMap converted as JSON String in JSP -
in spring controller: returning map values json string
map keyttlmap = getrediscachettlvalues(filterpattern);
jsonobject jsonobject = new jsonobject();
jsonobject.put("cachettlmap", keyttlmap);
return jsonobject.tostring();
in jsp ajax call:
var json = xmlhttp.responsetext; ( var = 0; < json.cachettlmap.length; i++) { var obj = json.cachettlmap[i]; ( var key in obj) { name = key; value = obj[key].tostring(); alert("name "+name +" value "+value); } }
json string value:
{ "cachettlmap": { "product1":81213,
"product2":79936 }}
when try run jsp, json string cannot iterated.is there simple way display hashmap in ajax, kindly me this. thanks!
var json = '[{"userid" : "123123", "password": "fafafa", "age": "21"}, {"userid" : "321321", "password" : "nana123", "age" : "34"}]'; var list = json.parse(json); var output = {}; for(var i=0; i<list.length; i++) { for(var key in list[i]) { if(list[i].hasownproperty(key)) { if(typeof output[key] == 'undefined') { output[key] = []; } output[key].push(list[i][key]); } } } document.write(json.stringify(output));
Comments
Post a Comment