JsonLint中的Json错误无效

时间:2014-02-10 10:46:08

标签: json jsonlint

我有一个返回json的网络服务:

[
    {
        "id": "9469",
        "title": "A person grabbed by police because being Nigerian he was carrying a Ghanaian passport!",
        "introtext": "A person has grabbed by police because being Nigerian he was having a Ghanaian passport! 

An individual has gotten by police on the grounds that being Nigerian he was having a Ghanaian visa! 

A 29-year-old Nigerian has been captured for endeavoring to get a visa with a falsely acquired Ghanaian travel permit."
    }
]

JSONLint发出以下错误:

Parse error on line 5:
...       "introtext": "A person has grabbe
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

我真的无法理解是什么让json无效?是换行还是什么?我能做些什么才能让它发挥作用?感谢。

3 个答案:

答案 0 :(得分:1)

在introtex中出现新行,这是有效的json检查

         [
        {
            "id": "9469",
            "title": "A person grabbed by police because being Nigerian he was carrying a Ghanaian passport!",
            "introtext": "A person has grabbed by police because being Nigerian he was having a Ghanaian passport! An individual has gotten by police on the grounds that being Nigerian he was having a Ghanaian visa! A 29-year-old Nigerian has been captured for endeavoring to get a visa with a falsely acquired Ghanaian travel permit."
        }
    ]

答案 1 :(得分:0)

将整个字符串放在一行中。 示例

[
{
    "id": "9469",
    "title": "A person grabbed by police because being Nigerian he was carrying a Ghanaian passport!",
    "introtext": "A person has grabbed by police because being Nigerian he was having aGhanaian passport!  An individual has gotten by police on the grounds that being Nigerian he was having a Ghanaian visa! A 29-year-old Nigerian has been captured for endeavoring to get a visa with a falsely acquired Ghanaian travel permit."
}

如果您想使用换行符

"introtext": "A person has grabbed by police because \n being Nigerian he was having aGhanaian passport!  An individual has gotten by police on the grounds that being Nigerian he was having a Ghanaian visa! A 29-year-old Nigerian has been captured for endeavoring to get a visa with a falsely acquired Ghanaian travel permit."

答案 2 :(得分:-1)

感谢@MONTYHS和@AvinashGarg指出错误。换行导致无效的JSON。要在我的json中使用断行,我将使用特殊字符替换所有换行标记<br/>,例如|~(酒吧和代字号)。在客户端,在解析json之后,我将|~的出现替换为<br/>以正确显示。

希望它有所帮助。参考是here

相关问题