如何解决javascript错误SyntaxError:缺少:属性ID后
尝试在对象数组内创建字符串数组,并得到一条错误消息,提示SyntaxError:missing:JavaScript以下代码的属性ID之后
let movies = [
{
movie title: 'Avengers: Age of Ultron',release year: '2015',rating:'7.3',"genres"=[0:"Action",1:"Adventure",2:"Sci-Fi"]
},{
movie title: 'The Dark Knight',release year:'2008',rating:'9.0',genres:["Action","Crime","Drama"]
},{
movie title: 'Forrest Gump',release year:'1994',rating:'8.8',genres:["Drama","Romance"]
},{
movie title: 'Inception',release year:'2010',"Adventure","Sci-Fi"]
},{
movie title: 'The Matrix',release year:'1999',rating:'8.7',{
movie title: 'Border',release year:'1997',rating:'7.9',"Drama","History"]
}
];
解决方法
您的代码中有两个错误。
- 如果JSON对象键包含'',则应输入“。
- 您不需要为JSON对象值编写索引。
这是更新的代码。
let movies = [
{
"movie title": 'Avengers: Age of Ultron',"release year": '2015',rating:'7.3',genres:["Action","Adventure","Sci-Fi"]
},{
"movie title": 'The Dark Knight',"release year":'2008',rating:'9.0',"Crime","Drama"]
},{
"movie title": 'Forrest Gump',"release year":'1994',rating:'8.8',genres:["Drama","Romance"]
},{
"movie title": 'Inception',"release year":'2010',{
"movie title": 'The Matrix',"release year":'1999',rating:'8.7',{
"movie title": 'Border',"release year":'1997',rating:'7.9',"Drama","History"]
}
];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。