How to read JSON array with @ # tags in data using jQuery,
{
"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
精彩评论