Looping through JSON arrays
- by George
I'm trying to pull the field names in the header of some JSON output. The following is a sample of the JSON header info:
{"HEADER":{"company":{"label":"Company Name"},"streetaddress":{"label":"Street Address"},"ceo":{"label":"CEO Name","fields":{"firstname":{"label":"First Name"},"lastname":{"label":"Last Name"}}}
I'm able to loop through the header and output the field and label (i.e. company and Company Name) using the following code:
obj = JSON.parse(jsonResponse);
for (var key in obj.HEADER) {
response.write ( obj.HEADER[key].label );
response.write ( key );
}
but can't figure out how to loop through and output the sub array of fields (i.e. firstname and First Name).
Any ideas?