gpt4 book ai didi

javascript - 代码不会验证

转载 作者:行者123 更新时间:2023-11-27 22:59:07 25 4
gpt4 key购买 nike

Json lint 不会验证我的代码。你知道为什么吗?

这是更新后的代码。它是一个对象,包括学校和在线教育。

var education ={
"schools": [
{
"name": "University of Hertfordshire",
"location": "Hertfordshir e, UK",
"degree": "Masters",
"Major": ["Computer Science"],
"graduation": "2017 (expected)"
},
{
"name": "University of Applied Sciences",
"location": "Jena, German",
"degree": "Diplom",
"Major": ["Business Administration and Information Systems"],
"graduation": "2010"
}
]
} ,

"onlineCourses": [
{
"title": "Javascript Syntax",
"school": "Udacity",
"dates": "May 2016"
}]
}

最佳答案

{
"schools": [{
"name": "University of Hertfordshire",
.....
}, {
"name": "University of Applied Sciences",
.....
}]
}, {
"onlinecourse": [{
"title": "Javascript Syntax",
....
}]
}

这里有 2 个物体悬空,需要位于 [] 内喜欢

 [
{
"schools": [{
"name": "University of Hertfordshire"
.....
}, {
"name": "University of Applied Sciences"
....
}]
}, {
"onlinecourse": [{
"title": "Javascript Syntax"
.....
}]
}
]

编辑

在更新的代码中

{
"schools": [
{
"name": "University of Hertfordshire"
.....
},
{
"name": "University of Applied Sciences"
.....
} ]
} ,

"onlineCourses": [
{
"title": "Javascript Syntax"
......
}]
}

注意}之后schools数组充当对象结束标记,并且没有 {之前onlinecourse向解析器建议 onlinecourse是另一个对象的一部分,并且由于所有这些困惑,解析器认为您有多个根元素。解决办法如下:

[      // json is contained in an array bcoz there are multiple objects 
{
"schools": [
{
"name": "University of Hertfordshire"
},
{
"name": "University of Applied Sciences"
}
]
},{ // the `}` your code was missing

"onlineCourses": [
{
"title": "Javascript Syntax"
}]
}
] // end of json array

当然,在验证时将注释从 json 中取出,因为 json 中不允许注释。

关于javascript - 代码不会验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37289612/

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