Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON-应为'EOF',Get','_Json_D3.js - Fatal编程技术网

JSON-应为'EOF',Get','

JSON-应为'EOF',Get',',json,d3.js,Json,D3.js,在jsonlint上,以下JSON显示错误:应为“EOF”,应为“GET”。问题显示在第10行的逗号处 { "name": "Professional", "children": [{ "name": "Professional Behavours" }, { "name": "Self-Care and Self-Awareness"

在jsonlint上,以下JSON显示错误:应为“EOF”,应为“GET”。问题显示在第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。根可以是对象{}或数组[]

在您的情况下,我选择数组:

[
    {
        "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"
            }
        ]
    }
]
或者,如果要将根作为对象:

{
    "a" : {
        "name": "Professional",
        "children": [
            {
                "name": "Professional Behavours"
            },
            {
                "name": "Self-Care and Self-Awareness"
            },
            {
                "name": "Medical Ethics and Law"
            }
        ]
    },
    "b": {
        "name": "Leader",
        "children": [
            {
                "name": "Teamwork and Leadership"
            },
            {
                "name": "Collaborative Practice"
            },
            {
                "name": "Health Systems and Careers"
            }
        ]
    }
}

您有多个根对象,因此不是有效的JSON。根可以是对象{}或数组[]

在您的情况下,我选择数组:

[
    {
        "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"
            }
        ]
    }
]
或者,如果要将根作为对象:

{
    "a" : {
        "name": "Professional",
        "children": [
            {
                "name": "Professional Behavours"
            },
            {
                "name": "Self-Care and Self-Awareness"
            },
            {
                "name": "Medical Ethics and Law"
            }
        ]
    },
    "b": {
        "name": "Leader",
        "children": [
            {
                "name": "Teamwork and Leadership"
            },
            {
                "name": "Collaborative Practice"
            },
            {
                "name": "Health Systems and Careers"
            }
        ]
    }
}

因为JSON除了末尾的一个额外的}之外还有多个根元素。这就是它看起来的样子

{
  ...
}, // <-- It expects EOF but gets ','
{
  ...
}
因此,当您添加[]时,它将成为一个数组,现在它有一个有效的根元素,即

[
  {
    ...
  },
  {
    ...
  }
]

因为JSON除了末尾的一个额外的}之外还有多个根元素。这就是它看起来的样子

{
  ...
}, // <-- It expects EOF but gets ','
{
  ...
}
因此,当您添加[]时,它将成为一个数组,现在它有一个有效的根元素,即

[
  {
    ...
  },
  {
    ...
  }
]

我知道这是有效的,但d3.js不允许外方括号。@IlludiumPu36我添加了一个对象版本,您需要指定像a、b这样的键或任何您想指定的键。我知道这是有效的,但d3.js不允许外方括号。@IlludiumPu36我添加了一个对象版本,您需要指定像a、b这样的键或任何您想要的键