如何使用jQuery读取数据中带有@#标签的JSON数组, [英] How to read JSON array with @ # tags in data using jQuery,

查看:81
本文介绍了如何使用jQuery读取数据中带有@#标签的JSON数组,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
    "locenter": [
        {
            "loname": {
                "@empid": "1001",
                "#text": "FE1"
            },
            "centers": [
                {
                    "@id": "0000100001",
                    "#text": "dcgiDal"
                }
            ]
        },
        {
            "loname": {
                "@empid": "1002",
                "#text": "FE2"
            },
            "centers": [
                {
                    "@id": "0000300006",
                    "#text": "dcgiDah"
                },
                {
                    "@id": "0000100006",
                    "#text": "dcgiDau"
                }
            ]
        }
    ]
}

推荐答案

与读取任何其他JSON相同的方法:jQuery.parseJSONJSON.parse.简化:

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

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

如果您将jQuery.ajaxdatatype'json'结合使用(并且可能会猜到),它将为您完成此操作.

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

在解析它之后,您可能必须使用类似数组的语法来访问属性.至少在Firefox中,这仅对于数字符号是必需的:

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']);

演示

这篇关于如何使用jQuery读取数据中带有@#标签的JSON数组,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆