gpt4 book ai didi

javascript - 从 JSON 数据获取特定属性

转载 作者:行者123 更新时间:2023-11-28 12:14:01 25 4
gpt4 key购买 nike

我的 api 调用有这个结果 JSON 数据,但是当我尝试访问属性“69106658_5”中的数据时,我无法访问,我收到“错误:未捕获的语法错误:无效或意外的 token ”。我有一个在下面的在线编辑器上运行的副本。我猜测是因为该属性包含下划线。

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']

关于javascript - 从 JSON 数据获取特定属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53728948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com