<分区>
如何将以下 JSON 类型转换为 javascript 数组?
[
{
"Product Name":"CPE 10281",
"Application":"Tyres",
"Weight":150,
"Cost to Produce":5000,
"Grade":"A",
"Cost to Sell":40000,
"Strength":100
},
{
"Product Name":"CPE 10282",
"Application":"computers",
"Weight":250,
"Cost to Produce":4000,
"Grade":"H",
"Cost to Sell":25000,
"Strength":90
},
{
"Product Name":"CPE 10283",
"Application":"paint",
"Weight":150,
"Cost to Produce":5000,
"Grade":"A",
"Cost to Sell":15000,
"Strength":90
}
]
与产品名称相关的任何给定条目的调用程序是什么?
感谢大家的意见和解决方案。到目前为止我所拥有的是
$.ajax({
url: "dataProductJSON.json",
dataType: 'json',
mimeType: "application/json",
success: function (data) {
$.each(data, function (key, val){
$.each(val, function (innerKey, innerValue){
item.push('<li id="' + innerKey + '">' + innerKey +" : " + innerValue + '</li>');
});
});
alert (item[2]);
$('<ul/>', {
'class': 'interest-list',
html: item.join('')
}).appendTo('body');
},
});
我的问题是从 JSON 文件中读取数据后如何将其转换为 javascript 数组。