我想将JSON数据推送到多维数组中。
我有类似下面的JSON数据并且已经解析了它。但是我无法将数据添加到数组中。下面的JSON仅适用于一页。当我翻转第二页时,我也得到JSON并检查它是否存在于数组中。如果没有,我想将数据添加到数组。
JSON数据:
[{
"8":
{"hsid":8,"hstype":1,"width":472,"height":141,"xpos":71,"ypos":28,"title":"For example","angle":0,"shape":0,"hotspotbordercolor":null,"hotspotransparency":null,"gotopage":0},
"10":
{"hsid":10,"hstype":2,"width":120,"height":114,"xpos":422,"ypos":224,"title":"Link","angle":0,"shape":0,"hotspotbordercolor":null,"hotspotransparency":null,"gotopage":0},
"11":
{"hsid":11,"hstype":4,"width":105,"height":77,"xpos":434,"ypos":628,"title":"Go to Page-5","angle":0,"shape":0,"hotspotbordercolor":null,"hotspotransparency":null,"gotopage":5}
}]
我想要这种格式的数组:
myArray = {
1: //page no
{
8: //id
{
"hsid": 8,
"hstype": 1,
"width": 472,
"height": 141
},
10: //id
{
"hsid": 10,
"hstype": 2,
"width": 120,
"height": 114
}
},
2: //page no
{
11: //id
{
"hsid": 11,
"hstype": 4,
"width": 105,
"height": 77
},
15: //id
{
"hsid": 15,
"hstype": 1,
"width": 213,
"height": 207
}
}
};
答案 0 :(得分:0)
尝试这样的事情,它将是一个对象:http://jsfiddle.net/jjay225/MUCg9/
您可以将数据推送到另一个对象,然后使用var pageExist=$.grep(arrTest,function(e)
{
return e.hsid=='8';
});
我只是将'8'作为页码放在那里,但这可能是你的页面的变量no或者其他东西。 'arrTest'是我将数据推入的另一个对象。