Javascript 我如何访问;订单“;在这个JSON中(名称中有分号)?
昨天被问到了,但在他得到答复之前就关门了: HTTP响应:Javascript 我如何访问;订单“;在这个JSON中(名称中有分号)?,javascript,json,Javascript,Json,昨天被问到了,但在他得到答复之前就关门了: HTTP响应: { "entry": { "@xml:base": "https://API_PROC_SRV/", "@xmlns": "http://www.w3.org/2005/Atom", "@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", "@xmlns:d": "http://schemas.micr
{
"entry": {
"@xml:base": "https://API_PROC_SRV/",
"@xmlns": "http://www.w3.org/2005/Atom",
"@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
"@xmlns:d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
"id": "https://API_PROC_SRV/A_Order",
"title": {
"@type": "text",
"#text": "A_Order()"
},
"updated": "2020-02-29T07:33:28Z",
"category": {
"@term": "Type",
"@scheme": "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
"link": [],
"content": {
"@type": "application/xml",
"m:properties": {
"d:Order": "123456789"
}
}
}
}
var json = response;
var order = json.object.entry.content['m:properties']['d:Order']; // I intend to read Order no from the below response.
"TypeError: Cannot read property 'entry' of undefined
at null.js:27:25
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"
Javascript代码:
{
"entry": {
"@xml:base": "https://API_PROC_SRV/",
"@xmlns": "http://www.w3.org/2005/Atom",
"@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
"@xmlns:d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
"id": "https://API_PROC_SRV/A_Order",
"title": {
"@type": "text",
"#text": "A_Order()"
},
"updated": "2020-02-29T07:33:28Z",
"category": {
"@term": "Type",
"@scheme": "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
"link": [],
"content": {
"@type": "application/xml",
"m:properties": {
"d:Order": "123456789"
}
}
}
}
var json = response;
var order = json.object.entry.content['m:properties']['d:Order']; // I intend to read Order no from the below response.
"TypeError: Cannot read property 'entry' of undefined
at null.js:27:25
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"
错误(例如jsbin.com):
{
"entry": {
"@xml:base": "https://API_PROC_SRV/",
"@xmlns": "http://www.w3.org/2005/Atom",
"@xmlns:m": "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
"@xmlns:d": "http://schemas.microsoft.com/ado/2007/08/dataservices",
"id": "https://API_PROC_SRV/A_Order",
"title": {
"@type": "text",
"#text": "A_Order()"
},
"updated": "2020-02-29T07:33:28Z",
"category": {
"@term": "Type",
"@scheme": "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
"link": [],
"content": {
"@type": "application/xml",
"m:properties": {
"d:Order": "123456789"
}
}
}
}
var json = response;
var order = json.object.entry.content['m:properties']['d:Order']; // I intend to read Order no from the below response.
"TypeError: Cannot read property 'entry' of undefined
at null.js:27:25
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"
根据,响应是有效的JSON
json.object.entry
显然是错误的。。。但是
问:当m:properties
和d:order
在名称中都有分号时,访问“order”值(名为d:order
)的正确Javascript语法是什么
注:我提名维杰的原始问题重新开放。。。但我并不乐观。这就是我的新问题。您需要解析JSON。任何地方都没有
对象
属性,它是jutjson.entry.content
响应=`{
“条目”:{
“@xml:base”:”https://API_PROC_SRV/",
“@xmlns”:”http://www.w3.org/2005/Atom",
“@xmlns:m”:”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
“@xmlns:d”:”http://schemas.microsoft.com/ado/2007/08/dataservices",
“id”:”https://API_PROC_SRV/A_Order",
“标题”:{
“@type”:“text”,
“#文本”:“订单()
},
“更新”:“2020-02-29T07:33:28Z”,
“类别”:{
“@term”:“Type”,
“@方案”:”http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
“链接”:[],
“内容”:{
“@type”:“application/xml”,
“m:属性”:{
“d:订单”:“123456789”
}
}
}
}`;
var json=json.parse(响应);
var order=json.entry.content['m:properties']['d:order'];
控制台日志(订单)代码>您需要解析JSON。任何地方都没有对象
属性,它是jutjson.entry.content
响应=`{
“条目”:{
“@xml:base”:”https://API_PROC_SRV/",
“@xmlns”:”http://www.w3.org/2005/Atom",
“@xmlns:m”:”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
“@xmlns:d”:”http://schemas.microsoft.com/ado/2007/08/dataservices",
“id”:”https://API_PROC_SRV/A_Order",
“标题”:{
“@type”:“text”,
“#文本”:“订单()
},
“更新”:“2020-02-29T07:33:28Z”,
“类别”:{
“@term”:“Type”,
“@方案”:”http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
},
“链接”:[],
“内容”:{
“@type”:“application/xml”,
“m:属性”:{
“d:订单”:“123456789”
}
}
}
}`;
var json=json.parse(响应);
var order=json.entry.content['m:properties']['d:order'];
控制台日志(订单)代码>你所拥有的似乎是正确的。不确定对象在那里做什么。请尝试json.entry.content['m:properties']['d:Order']
。您所做的似乎是正确的。不确定object
在其中做什么。请尝试json.entry.content['m:properties']['d:Order']
。