Reputation: 4827
I have the following data passed in from a URL. All of the examples I've seen on recursively printing a JSON object deal with an object that is symmetrical e.g. this one. But how would I print the following in a DIV when each element has a specific name? Do I have to manually reference each field?
I am new to JSON, so any help would be appreciated.
var data = {
{
"Message": "success",
"Status": "done",
"providerResponse": {
"referenceNumber": "9876542",
"errorCode": "0",
"errorMessage": "Approved",
"accountNum": "XXXXXXXXXXXX0109",
"expirationDate": "0116",
"customerName": "MILTON BERLE",
"customerAddress1": "614 BROADWAY",
"customerCity": "NEW YORK",
"customerState": "NY",
"customerZIP": "01019",
}
}
};
Upvotes: 1
Views: 167
Reputation:
No, you don't. You loop through the keys one by one.
var obj = JSON.parse(jsonString);
for (key in obj) {
alert(key + " = " + obj[key]);
// or do other stuff with the keys and values
}
Upvotes: 2