我有一个以下格式的json对象,我正在尝试为 krishna kk 键检索成绩,这会给我Uncaught SyntaxError: Unexpected token [
错误。任何人都可以帮助理解如何获取键名在其中有空格的内部对象数据。
[
{"studentinfo": [
{
"rama nathan": {
"grade": "1",
"roleno": "9",
"score": 9
}
},
{
"krishna kk": {
"grade": "3",
"roleno": "9",
"score": 4
}
},
{
"john Doe": {
"grade": "2",
"roleno": "5",
"score": 7
}
}
],
}
]
我的代码如下:
var stugrade = studentobject["0"].studentinfo["0"].[rama nathan].grade;
答案 0 :(得分:1)
您可以像这样执行
var stugrade = studentobject[0].studentinfo[0]['rama nathan']['grade'];
答案 1 :(得分:0)
将[rama nathan]
更改为["rama nathan"]
。这是调用JavaScript对象属性的方法。像这样使用它:
var stugrade = studentobject["0"].studentinfo["0"]["rama nathan"].grade;