JSON 解析错误:期待“STRING”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34551210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:12:26  来源:igfitidea点击:

JSON Parse Error: Expecting 'STRING'

json

提问by yitzih

I am using JSONLintto parse some JSON and i keep getting the error:

我正在使用JSONLint来解析一些 JSON,但我不断收到错误消息:

Error: Parse error on line 1: [{“ product”: [{“
---^ Expecting 'STRING', '}', got 'undefined'

错误:第 1 行解析错误:[{“ product”: [{“
---^ Expecting 'STRING', '}', got 'undefined'

This is the code:

这是代码:

[
    {
        “product” :  [ { “code” : “Abc123”, “description” : “Saw blade”, “price” : 34.95 } ],
        “vendor” : [ { “name” : “Acme Hardware”, “state” : “New Jersey” } ]
    },

    {
        “product” :  [ { “code” : “Def456”, “description” : “Hammer”, “price” : 22.51 } ],
    },

    {
        “product” :  [ { “code” : “Ghi789”, “description” : “Wrench”, “price” : 12.15 } ],
        “vendor” : [ { “name” : “Acme Hardware”, “state” : “New Jersey” } ]
    },

    {
        “product” :  [ { “code” : “Jkl012”, “description” : “Pliers”, “price” : 14.54 } ],
        “vendor” : [ { “name” : “Norwegian Tool Suppliers”, “state” : “Kentucky” } ]
    }
]   

回答by SLaks

JSON string literals must use normal quote characters ("), not smart quotes (“”).

JSON 字符串文字必须使用普通引号字符 ( "),而不是智能引号 ( “”)。

回答by 11thdimension

You're using some unicode double quotes characters. Replace them with the normal "double quotes.

您正在使用一些 unicode 双引号字符。用普通的"双引号替换它们。

You also had some extra comma at the end in the second element.

在第二个元素的末尾还有一些额外的逗号。

Now it's alright

现在好了

[
    {
        "product" :  [ { "code" : "Abc123", "description" : "Saw blade", "price" : 34.95 } ],
        "vendor" : [ { "name" : "Acme Hardware", "state" : "New Jersey" } ]
    },

    {
        "product" :  [ { "code" : "Def456", "description" : "Hammer", "price" : 22.51 } ]
    },
    {
        "product" :  [ { "code" : "Ghi789", "description" : "Wrench", "price" : 12.15 } ],
        "vendor" : [ { "name" : "Acme Hardware", "state" : "New Jersey" } ]
    },
    {
        "product" : [ { "code" : "Jkl012", "description" : "Pliers", "price" : 14.54 } ],
        "vendor" : [ { "name" : "Norwegian Tool Suppliers", "state" : "Kentucky" } ]
    }
]