开发者

How to read JSON array with @ # tags in data using jQuery,

开发者 https://www.devze.com 2023-02-03 11:02 出处:网络
{ \"locenter\": [ { \"loname\": { \"@empid\": \"1001\", \"#text\": \"FE1\" }, \"centers\": [ { \"@id\": \"0000100001\",
{
    "locenter": [
        {
            "loname": {
                "@empid": "1001",
                "#text": "FE1"
            },
            "centers": [
                {
                    "@id": "0000100001",
                    "#text": "dcgiDal"
                }
            ]
        },
        {
            "loname": {
                "@empid": "1002",
                "#text": "FE2"
            },
            "centers": [
                {
                    "@id": "0000300006",
                    "#text": "dcgiDah"
   开发者_Python百科             },
                {
                    "@id": "0000100006",
                    "#text": "dcgiDau"
                }
            ]
        }
    ]
}


The same way you read any other JSON: jQuery.parseJSON or JSON.parse. Simplified:

var o = jQuery.parseJSON('{"loname": { "@empid": "1001", "#text": "FE1" } }');

If you use jQuery.ajax with datatype 'json' (and possibly if you let it guess), it will do this for you.

After parsing it, you may have to use the array-like syntax to access properties. In Firefox at least, this is only necessary for the number sign:

alert(o.loname['#text']);

Demo

0

精彩评论

暂无评论...
验证码 换一张
取 消