我有一个web服务返回下面的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在这里无效?是换行符还是怎么的?我能做些什么来让它工作呢?谢谢。
发布于 2014-02-10 18:48:35
在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-10 18:51:47
将您的整个字符串放在一行中。示例
[
{
"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-10 19:32:41
感谢@MONTYHS和@AvinashGarg指出错误。换行符导致无效的JSON。为了在我的json中换行,我用一个特殊的字符,例如|~ (bar和波浪号)替换了所有的换行符<br/>。在客户端,在解析json之后,我用<br/>替换了出现的|~,以便正确显示。
希望这能帮助到别人。引用是here。
https://stackoverflow.com/questions/21675038
复制相似问题