3

我想将 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
        }
    }
};
4

1 回答 1

0

尝试这样的事情,这将是一个对象:http: //jsfiddle.net/jjay225/MUCg9/ 您可以将数据推送到另一个对象中,然后使用var pageExist=$.grep(arrTest,function(e) { return e.hsid=='8'; }); 我只是将“8”作为页码放在那里,但这可能成为您的页面 no 或其他东西的变量。'arrTest' 是我将数据推送到的另一个对象。

于 2013-06-12T12:43:30.043 回答