【发布时间】:2015-07-04 04:21:33
【问题描述】:
我目前正在从如下所示的 JSON 数组中提取数据
"title": Title,
"chapters": {
"13c": {
"words": 123,
"spaces": 321
},
"15d": {
"words": 123,
"spaces": 321
},
"38h": {
"words": 123,
"spaces": 321
}
}
问题是当我尝试使用以下内容选择 13c(如果存在)时
if(book.chapters.13c){
console.log(book.chapters.13c);
}
我收到以下错误:
Uncaught SyntaxError: Unexpected token ILLEGAL
【问题讨论】:
-
变量名不能以数字开头。这就是它抛出错误的原因。
-
有没有办法绕过这个?
-
c13 将是一个有效的变量名
-
是的,有办法绕过这个。
标签: javascript jquery arrays json