0

我有一个返回以下 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 在这里无效?是换行还是什么?我该怎么做才能让它发挥作用?谢谢。

4

3 回答 3

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."
        }
    ]
于 2014-02-10T10:48:34.740 回答
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."
于 2014-02-10T10:51:47.193 回答
-1

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

希望它可以帮助某人。参考在这里

于 2014-02-10T11:32:41.307 回答