【问题标题】:Can't Parse Json无法解析 Json
【发布时间】:2017-05-14 19:03:30
【问题描述】:

我正在尝试将 JSON 发送到一个用 Spring 编写的 REST 控制器,无论我尝试了什么 - Jackson 都会抛出异常:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Illegal character ((CTRL-CHAR, code 10)): 

这是 JSON:

{"fact checking": [ {"fact": "Clinton Foundation has no ships, didn’t smuggle refugees", "status":"false","source":"http://www.politifact.com/punditfact/statements/2017/may/12/blog-posting/fake-news-clinton-foundation-has-no-ships-didnt-sm/", "actual":"One way to tell if the story is made up, beyond its absurdity, is a link allegedly to a CNN story that is actually to a Forrest Gump meme that reads, "Are you stupid or something?""}, {"fact":"AG Jeff Sessions claims district attorneys charge immigrants for lesser crimes", "source":"http://www.politifact.com/truth-o-meter/statements/2017/may/10/jeff-sessions/sessions-claims-district-attorneys-charge-immigran/", "status":"half true", "actual":"Sessions spoke about "criminal aliens," a term generally applied to non-U.S. citizens – living in the United States legally or illegally – who are convicted of crimes."}, {"fact":"Is Sean Spicer Wearing Mismatched Shoes?", "source":"http://www.snopes.com/sean-spicer-shoes/", "status":"true", "actual":"A photograph showing the White House press secretary wearing two different types of footwear is real, but the oddity appears to serve a medical purpose rather than an avant-garde fashion choice."} ]}

有什么建议吗?

【问题讨论】:

标签: json spring jackson


【解决方案1】:

我已将您的 JSON 文档粘贴到 JSON formatter 中,如您所见,它抱怨位置 404 出现意外标记。 那是因为您没有正确地转义文档,并且位置 404 处的双引号 (") 使解析器感到困惑。 您应该转义出现在键/值中的引号,将它们替换为 \" (或 \' 用于单引号)。

转义字符串后,formatter解析文档成功

【讨论】:

    【解决方案2】:

    您的 JSON 在字符串值中有 2 个双引号。见截图。

    我认为从源返回的 JSON 不正确或您提供的字符编码不正确。

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多