JSON 验证需要“EOF”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22151760/
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 17:10:51  来源:igfitidea点击:

JSON Validation Expecting 'EOF'

json

提问by Jordan.J.D

I am working on a restful api and have been validating with http://jsonlint.com/. After combining two JSON objects I ran into;

我正在开发一个宁静的 api,并且一直在使用http://jsonlint.com/进行验证。在组合两个 JSON 对象后,我遇到了;

Parse error on line 932:
...ssions": 329    }],[    {        "m
---------------------^
Expecting 'EOF'

I looked around and found thisquestion but all of the answers point to not having a comma, where in my problem I do have a comma. What else could the validator be looking for?

我环顾四周,发现了这个问题,但所有答案都指向没有逗号,在我的问题中,我确实有逗号。验证器还能寻找什么?

it is pointing at the code between my object arrays;

它指向我的对象数组之间的代码;

],
[

回答by T.J. Crowder

You haven't shown enough of your JSON, but I'm guessing it looks like this:

你没有展示足够的 JSON,但我猜它看起来像这样:

[
    {"some": "object"},
    {"some": "object"}
],
[
    {"some": "object"},
    {"some": "object"}
]

...which is invalid. In JSON, there must be onetop-level item (which in a complete JSON document must either an object or an array).

...这是无效的。在 JSON 中,必须有一个顶级项目(在完整的 JSON 文档中必须是一个对象或一个数组)。

If you're combining two responses, you might make each of them the value of a property on a wrapper object, e.g.:

如果您将两个响应组合在一起,您可以将它们中的每一个设为包装器对象上的属性值,例如:

{
    "response1": [
        {"some": "object"},
        {"some": "object"}
    ],
    "response2": [
        {"some": "object"},
        {"some": "object"}
    ]
}

回答by santhosh shankar

I am no expert on multi root JSON structures But here is what I did.. Just changed the encoding of the stream to UTF-8 and my PHP code started working very well

我不是多根 JSON 结构方面的专家,但这是我所做的.. 只需将流的编码更改为 UTF-8,我的 PHP 代码就开始工作得很好

回答by Talha Awan

In my case, it was a semi-colon at the end of JSON object that was throwing this error on jsonlint:

就我而言,它是 JSON 对象末尾的分号,在jsonlint上抛出此错误:

Expecting 'EOF', '}', ',', ']', got 'undefined'

Removing that solved it.

删除它解决了它。

回答by ovaisbhat

remove doubles quotes from brackets [

从括号中删除双引号 [