[英]How to interpret JSON field with '-' in node.js
I am using the node.js to interpret a JSON data, the data format is like this below 我正在使用node.js解释JSON数据,数据格式如下所示
{
"href": "https://localhost/light/0000293D",
"i-object-metadata": [
{
"rel": "temperature",
"val": "244"
}
]
}
I can print the raw data using print (body)
to interpret data all works except printing the field i-object-metadata
我可以使用
print (body)
打印原始数据来解释数据,除了打印字段i-object-metadata
以外,所有工作都可以进行
var obj = JSON.parse(body);
console.log(obj.items); // works well
console.log(obj.i-object-metadata); // error
How could I interpret the JSON object like this i-object-metadata
我如何解释像这样的JSON对象
i-object-metadata
在这种情况下,不能使用对象的简写形式,必须使用数组符号:
console.log(obj['i-object-metadata'].val); // 244
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.