[英]Extract Values from JSON Object
I have the following data passed in from a URL. 我从URL传递了以下数据。 All of the examples I've seen on recursively printing a JSON object deal with an object that is symmetrical eg this one. 我在递归打印JSON对象时看到的所有示例都处理一个对称对象,例如此对象。 But how would I print the following in a DIV when each element has a specific name? 但是,当每个元素都有特定的名称时,如何在DIV中打印以下内容? Do I have to manually reference each field? 我是否必须手动引用每个字段?
I am new to JSON, so any help would be appreciated. 我是JSON新手,所以将不胜感激。
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",
}
}
};
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.