如何在jQuery中提取以下JSON并将其显示在警告框中?
{
"ID": null,
"ResponseCode": "0",
"ResponseMessage": "Success...",
"Data": [{
"PARAMETER": "चुना",
"QUANTITY": "500",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "सल्फर",
"QUANTITY": "20",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "जिप्सम",
"QUANTITY": "0",
"UNIT": "MT",
"METHOD": null
}, {
"PARAMETER": "फॉस्फरिक एसिड",
"QUANTITY": "16",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "सल्फुरिक एसिड",
"QUANTITY": "4",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "मल्चिंग ",
"QUANTITY": "मल्चिंग",
"UNIT": "-",
"METHOD": null
}],
}
答案 0 :(得分:1)
var data = [
{
"ID": null,
"ResponseCode": "0",
"ResponseMessage": "Success...",
"Data": [{
"PARAMETER": "चुना",
"QUANTITY": "500",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "सल्फर",
"QUANTITY": "20",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "जिप्सम",
"QUANTITY": "0",
"UNIT": "MT",
"METHOD": null
}, {
"PARAMETER": "फॉस्फरिक एसिड",
"QUANTITY": "16",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "सल्फुरिक एसिड",
"QUANTITY": "4",
"UNIT": "किलो",
"METHOD": null
}, {
"PARAMETER": "मल्चिंग ",
"QUANTITY": "मल्चिंग",
"UNIT": "-",
"METHOD": null
}]
}
];
var vData="";
$.each(data, function(index, element) {
$.each(element.Data, function(index2, element2) {
vData+=element2.PARAMETER+" ";
});
});
alert(vData);
答案 1 :(得分:0)
这是你想要的那种东西吗?
var example_json='{"ID": null,"ResponseCode": "0"}';
alert(JSON.stringify(example_json));
或者如果你想要花哨
var example_json='{"ID": null,"ResponseCode": "0"}';
alert(JSON.stringify(JSON.parse(example_json)));