【问题标题】:JSON: how to deal with double quotations?JSON:如何处理双引号?
【发布时间】:2011-11-16 05:10:33
【问题描述】:

我正在使用 SBJson 来解析 JSON 字符串。有些请求会返回这样的想法:

{
"jsonResponse":[{  
"id":"2",  
"name":"Somename",  
"title":"Json problem:"ErrorParsing"", //problem is here. with double quotations. how to remove them or remove error? When i delete brackets before and after ErrorParsing, it works good.  
"otherinfo":"blabla",  
}]
}

【问题讨论】:

  • 我不确定你所说的双括号是什么意思。无论如何,这不是一个有效的 JSON 字符串,因此它可能是您正在使用的 Web 服务中的问题。
  • 双括号它是括号中的括号,例如:“Hello“World””
  • 那么这是Web服务问题。谢谢
  • 修复了这个问题。他指的不是括号,而是引号。

标签: objective-c ios parsing error-handling sbjson


【解决方案1】:

那些不是括号;它们是(双)引号/引号。在有效的 JSON 中,字符串中的引号 必须 用 \ 进行转义,例如"你好\"世界\""。

您正在使用的 Web 服务正在返回无效的 JSON。

http://jsonlint.com 是验证 JSON 字符串的有用资源。

【讨论】:

    【解决方案2】:

    我相信您的意思是“双引号”,而不是“双括号”。您需要在此处使用不同的引号,例如:

    "title":"Json problem:'ErrorParsing'"
    

    【讨论】:

    • 我无法控制网络响应,我收到了它,我需要解析它:)
    • 在这种情况下(并且与@Bavarious 的回答一致),您没有接收到有效的 JSON。您需要使用 Web 服务解决此问题。
    【解决方案3】:

    正确的json必须是

    {
    "jsonResponse":[{  
    "id":"2",  
    "name":"Somename",  
    "title":"Json problem:\"ErrorParsing\"", //problem is here. with double quotations. how to remove them or remove error? When i delete brackets before and after ErrorParsing, it works good.  
    "otherinfo":"blabla",  
    }]
    }
    

    我想你明白了

    【讨论】:

      猜你喜欢
      • 2021-01-08
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多