Looping through JSON arrays

Posted by George on Stack Overflow See other posts from Stack Overflow or by George
Published on 2010-04-08T15:43:40Z Indexed on 2010/04/08 15:53 UTC
Read the original article Hit count: 377

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about vbscript

Related posts about jscript