JSON语法错误......我没有看到它

时间:2014-11-07 14:51:36

标签: javascript json

jsonlint网站说那条线上有什么问题......我根本找不到它。 真正的文件大概是1000行,所以它可能会在文件后面出现问题,但我只想检查SO,因为我根本没有看到任何错误。

{
    "Blue Tag" : {
        "Queries" : {
            "DepartmentID" : {
                "name" : "Departments",
                "params" : ["1"],
                "options": []
            },
            "ZoneID" : {
                "name" : "Zones",
                "params" : [
                    "1",
                    "Department" : { // error here for some reason
                        "ref" : "true", 
                        "returns" : "value"
                    }
                ],
                "options": []
            },
            "MachineID" : {
                "name" : "Machines",
                "params" : [
                    "1",
                    "Department" : { 
                        "ref" : true, 
                        "returns" : "value"
                    },
                    "Zone" : { 
                        "ref" : true, 
                        "returns" : "value"
                    }
                ],
                "options": []
            }
        },
        "Emails" : ["*@*.com","*@*.com"],
        "PK" : "ID",
        "Table" : "BlueTags",
        "Connection" : "Safety"
    }
}

这是错误:

Parse error on line 17:
...        "Department": {                
-----------------------^
Expecting '}', ',', ']'

2 个答案:

答案 0 :(得分:2)

"params" : [
    "1",
    "Department" : { 
        "ref" : "true", 
        "returns" : "value"
    }
]

这是一个常规数组,而不是一个对象。将[]更改为{}

"params" : { // <- Curly brackets denote an object consisting of key:value pairs
    "1" : "",
    "Department" : { 
        "ref" : "true", 
        "returns" : "value"
    }
}

或者,如果你想将params保持为数值数组

"params" : [ // <- Square brackets denote an array consisting values (which can be, in turn, objects)
    "1",
    {"ref" : "true", "returns" : "value"}
]

答案 1 :(得分:0)

我想你只是忘记了params数组

中对象周围的括号
"params" : [
    "1",
    {"Department" : { 
        "ref" : true, 
        "returns" : "value"
    }},
    {"Zone" : { 
        "ref" : true, 
        "returns" : "value"
    }}
],