我有以下JSON:
{
"code": 201,
"data": {
"type": "Agent",
"id": {
"@type": "Client",
"@id": "88",
"title": "Ing.",
"titleAfter": null,
"name": "Ján",
"surname": "Kašperan",
"idNumber": "8706229411",
"dateOfBirth": null,
"idCardNumber": "OP12345",
"idCardExpirationDate": null,
"idCardType": {
"@type": "IdCardType",
"@id": 1,
"name": "id_card_type.id_card",
"shortName": "OP"
},
"type": 1
}
}
}
我想写一个JSON路径表达式,以便我想得到" @ id" 的价值:" 88",。
我的JSON路径不起作用:$ .data.id。@ id
答案 0 :(得分:0)
由于不允许@
,因此请通过字符串属性名称访问它。有关属性访问器的更多信息,请参见MDN
var json = {
"code": 201,
"data": {
"type": "Agent",
"id": {
"@type": "Client",
"@id": "88",
"title": "Ing.",
"titleAfter": null,
"name": "Ján",
"surname": "Kašperan",
"idNumber": "8706229411",
"dateOfBirth": null,
"idCardNumber": "OP12345",
"idCardExpirationDate": null,
"idCardType": {
"@type": "IdCardType",
"@id": 1,
"name": "id_card_type.id_card",
"shortName": "OP"
},
"type": 1
}
}
}
console.log(json.data.id["@id"])