I want to push JSON data into a multi-dimensional Array.
I have JSON data like below and already parsed it. But I'm not able to add the data to the array. The JSON below is only for one page. When I flip second page I also get JSON and check whether it exist in the array or not. If not, I want add the data to the array.
JSON data:
[{
"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}
}]
I want the array in this format:
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
}
}
};
Try something like this, it will be an object tho: http://jsfiddle.net/jjay225/MUCg9/ You can push your data into another object then use var pageExist=$.grep(arrTest,function(e) { return e.hsid=='8'; });
I just put '8' there as a page number for instance but that could be a variable for your page no or something too. 'arrTest' is the other object I pushed data into.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.