如何使用 jquery 获取唯一的商家名称以及相应的 avgprice 和 numproducts?我一直很难分离 json 数据。请帮帮我。我正在使用 $.getJSON 解析这个 json 文件。我们正在创建图表,我们需要在每个商家名称后使用分隔符。所以这里的 avgprice 和 numProducts 是 x 和 y 轴的值。所以如果我使用这样的东西
$.getJSON("mock/Insight72.json", function(returnedData) {
dataLength = returnedData.data.length;
console.log(returnedData)
response = returnedData;
var x = new Array();
var y = new Array();
var mytext, f;
for ( i = 0; i < dataLength; i++) {
x[i] = returnedData.data[i].avgPrice;
y[i] = returnedData.data[i].numProducts;
x 和 y 轴以相同的顺序存储。但我需要像它应该采用与商家名称对应的 avgprice 和 numProducts 一样进行解析。希望这能澄清..
{
"id" : "72",
"title" : "Item Category Product Level Average Price Comparison",
"xLabel" : null,
"yLabel" : "Average Price",
"zLabel" : null,
"data" : [
{
"avgPrice" : 10,
"categoryID" : "152b7934dd7e4fbeac56f825b5deaebd",
"categoryName" : "Coffee Makers",
"merchantID" : "99a8cd5687d245f8bff2152fec710973",
"merchantName" : "Crate & Barrel",
"numProducts" : 400
},
{
"avgPrice" : 20,
"categoryID" : "152b7934dd7e4fbeac56f825b5deaebd",
"categoryName" : "Coffee Makers",
"merchantID" : "f5b2c736eace488a859fb6c56f366522",
"merchantName" : "Williams-Sonoma",
"numProducts" : 500
},
{
"avgPrice" :30,
"categoryID" : "152b7934dd7e4fbeac56f825b5deaebd",
"categoryName" : "Coffee Makers",
"merchantID" : "6ee163f4f236466289fae97bb40351b7",
"merchantName" : "Amazon",
"numProducts" : 38
},
{
"avgPrice" : 40,
"categoryID" : "50215adc9ef64f91b4f4898fda7cf0b5",
"categoryName" : "Dishwashers",
"merchantID" : "99a8cd5687d245f8bff2152fec710973",
"merchantName" : "Crate & Barrel",
"numProducts" : 300
},
{
"avgPrice" : 50,
"categoryID" : "50215adc9ef64f91b4f4898fda7cf0b5",
"categoryName" : "Dishwashers",
"merchantID" : "f5b2c736eace488a859fb6c56f366522",
"merchantName" : "Williams-Sonoma",
"numProducts" : 320
},
{
"avgPrice" : 60,
"categoryID" : "50215adc9ef64f91b4f4898fda7cf0b5",
"categoryName" : "Dishwashers",
"merchantID" : "6ee163f4f236466289fae97bb40351b7",
"merchantName" : "Amazon",
"numProducts" : 350
}
]
}