json - JSON - 期待'EOF',得到','
问题描述
在 jsonlint 上,以下 JSON 显示错误:期望 'EOF',得到 ','。问题以第 10 行的逗号显示。
{
"name": "Professional",
"children": [{
"name": "Professional Behavours"
}, {
"name": "Self-Care and Self-Awareness"
}, {
"name": "Medical Ethics and Law"
}]
}, {
"name": "Leader",
"children": [{
"name": "Teamwork and Leadership"
}, {
"name": "Collaborative Practice"
}, {
"name": "Health Systems and Careers"
}]
}
}
添加外部方括号,JSON 显示为有效。
但是,我将 JSON 与 d3.js 一起使用,它不允许外部方括号。d3.js 也不将下面的 JSON 识别为有效。
这个 JSON 应该如何在没有外部方括号的情况下正确格式化?
更新
感谢您的回答,这有效:
{
"name": "Condition",
"children": [{
"name": "Professional",
"children": [{
"name": "Professional Behavours"
},{
"name": "Self-Care and Self-Awareness"
},{
"name": "Medical Ethics and Law"
}]
}, {
"name": "Leader",
"children": [{
"name": "Teamwork and Leadership"
},{
"name": "Collaborative Practice"
},{
"name": "Health Systems and Careers"
}]
}]
}
解决方案
}
因为您的 JSON 有多个根元素(除了末尾的额外元素)。这就是它的样子
{
...
}, // <-- It expects EOF but gets ','
{
...
}
一个有效的 JSON 应该有一个根元素,即
{
...
}
所以,当你添加[]
它时,它变成了一个数组,现在只有一个有效的根元素,即
[
{
...
},
{
...
}
]
推荐阅读
- postgresql - 更改唯一索引以在 postgresq 中将其设置为可延迟
- java - 构建您的第一个应用 DisplayMessageActivity textview 错误,应用在启动时崩溃
- javascript - Jasmine Javascript 测试
- vim - 如何自定义 vim 航空公司以根据文件长度更改颜色?
- swift - 如何快速检测标签栏索引的变化?
- php - datables 与 laravel 5.6 不兼容?
- python - 使用python将文件上传到SFTP
- c - 此 C 代码中用于使用矩阵乘法查找斐波那契的函数 multiplyTwoMatrices() 有什么问题?
- jquery - AjaxForm 函数第二次不起作用
- java - 检查回文