我有一个看起来像这样的 JSON 文件
{
"samlp:Response": {
"@attributes": {
"xmlns:samlp": "urn:oasis:names:tc:SAML:2.0:protocol",
"ID": "_482d7b9c-3e50-47cb-aa64-4e3655352c64",
"Version": "2.0",
"IssueInstant": "2019-06-27T17:02:47.711Z",
"Destination": "https://jjds-sunrise--cqsupport--c.cs102.visual.force.com/apex/ResponseReceiver",
"InResponseTo": "Azure_9849028456"
}
}
}
尝试使用正常方式解析此 JSON 时,即
jsonObject.samlp:Response.@attributes.ID
其中 jsonObject 是我为此 JSON 创建的对象。我收到一条错误消息
"unexpected token :"
.我做错了吗,还是有其他方法可以解析它?
最佳答案
看看 Property Accessors 。请考虑以下事项:
const jsonObject = {
"samlp:Response": {
"@attributes": {
"xmlns:samlp": "urn:oasis:names:tc:SAML:2.0:protocol",
"ID": "_482d7b9c-3e50-47cb-aa64-4e3655352c64",
"Version": "2.0",
"IssueInstant": "2019-06-27T17:02:47.711Z",
"Destination": "https://jjds-sunrise--cqsupport--c.cs102.visual.force.com/apex/ResponseReceiver",
"InResponseTo": "Azure_9849028456"
}
}
};
console.log(jsonObject["samlp:Response"]["@attributes"].ID);
关于javascript - 解析属性键中包含特殊字符的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56801172/