从JSON数据中获取特定属性



我的api调用有这个结果JSON数据,但当我试图访问属性"69106658_5"中的数据时,我无法访问,我会得到"错误:未捕获的语法错误:无效或意外的令牌"。我有一份我正在网上编辑的内容。我猜是因为属性包含下划线。

let results=
{
"links": {
"data": {
"self": {
"body": "",
"content_type": "",
"href": "/api/v2/nodes/69107289/categories",
"method": "GET",
"name": ""
}
}
},
"results": [
{
"data": {
"categories": {
"58652374_10": [
"16",
"16.0.1",
"16.2",
"16.2.4"
],
"58652374_11": [
"English"
],
"58652374_12": [
"Windows"
],
"58652374_13": "2018-11-20T00:00:00",
"58652374_2": "Published",
"58652374_3": "19",
"58652374_4": "Video",
"58652374_5": "65",
"58652374_6": "How To",
"58652374_7": [
"basic"
],
"58652374_8": "237",
"58652374_9": "Content Server"
}
}
},
{
"data": {
"categories": {
"69106658_2": "You Tube",
"69106658_3": [
"End User"
],
"69106658_4": [
"69106508:7"
],
"69106658_5": "https://img.youtube.com/vi/j-aOeCpRvEs/hqdefault.jpg",
"69106658_6": false,
"69106658_7": "Engineering",
"69106658_8": null
}
}
}
]
}
var lookInto = results.results;
for( let key in lookInto ) {
var selectData = lookInto[key].data.categories;
console.log(selectData);
}
console.log( selectData.69106658_5 )

以字母以外的任何字符(以及一些符号,如_(开头的属性字段,必须使用括号表示法才能访问。

尝试selectData['69106658_5']而不是selectData.69106658_5

下划线不应该引起任何问题。如果你想访问属性"69106658_5",你应该这样做:

results.results[1].data.categories["69106658_5"]

相关内容

  • 没有找到相关文章