JsonLint 中的 JSON 错误无效



我有一个返回以下json的Web服务:

[
    {
        "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 在这里无效?是换行符还是什么?我能做些什么来让它工作?谢谢。

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."
        }
    ]

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

[
{
    "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."

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

希望它对某人有所帮助。参考资料在这里。

相关内容

  • 没有找到相关文章

最新更新