How can i iterate my json string return from a Java file in JavaScript ?
My JSON string having the following hierarchy;
ResponseObject -> SId -> SeId -> QId-> List of data. I need to access that list of data by looping through it using JavaScript.
How can i iterate my json string return from a Java file in JavaScript ?
My JSON string having the following hierarchy;
ResponseObject -> SId -> SeId -> QId-> List of data. I need to access that list of data by looping through it using JavaScript.
You can use jQuery to parse JSON String or alternatively, you can create a JSON Object using the javascript eval() function.
Once you have a JSON object created, you can use dot notation to traverse your json, like
var value = ResponseObject.SId.SeId.Qid;
Where the attributes from the dot notation are your JSON key in the json string.
Use this notation: myobjet["MyAttributeName"].
for( var SId in ResponseObject ) {
for(var SeId in ResponseObject[SId] ) {
for(var QId in ResponseObject[SId][SeId] ) {
var value = ResponseObject[SId][SeId][QId];
}
}
}
I didn't test it, but it should work.