Iterate through JSON object using DOJO or javascript -
i have json object coming ajax resaponse.it looks this.
{ "customerid": "87545", "parentcustomerid": "parent:87545",
"relationshipid": "87545-- rel 1234", "customername": "87545-- john snow", "constitution": "87545-- consti" }
now want iterate through either using dojo 1.10 library or normal loop javascript.but not able loop through. have tried approach
require(["dojo/_base/array"], function(array){ array.foreach(json.stringify(ajaxjsondata), function(entry, i){ }); });
can anyont please me ?
nb: json object coming dynamically each time , keys same id of input types in jsp page. need key , value.
you can use following in javascript:
var obj = { "customerid": "87545", "parentcustomerid": "parent:87545", "relationshipid": "87545-- rel 1234", "customername": "87545-- john snow", "constitution": "87545-- consti" }; (var key in obj) { console.log(key +":" +obj[key]); }
explanation: iterate on keys present in obj
, print along corresponding value in obj
using obj[key]
.
you can check results copying above code in browser's console.
Comments
Post a Comment