【问题标题】:SBJSON failed with json including binary dataSBJSON 失败,包含二进制数据的 json
【发布时间】:2012-12-31 13:59:05
【问题描述】:

我正在使用 Web 服务并使用 sbjson 解析接收到的数据,如下所示:

NSDictionary *response = [[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]JSONValue];

它运行良好,但在包含二进制数据的 json 中失败(应用程序/pdf) 我在控制台中得到了这个:

-JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=6 \"Invalid high character in surrogate pair\" UserInfo=0x1e0e1700 {NSLocalizedDescription=Invalid high character in surrogate pair}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=6 \"Broken unicode character\" UserInfo=0x1e0e1740 {NSUnderlyingError=0x1e0e1720 \"Invalid high character in surrogate pair\", NSLocalizedDescription=Broken unicode character}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x1e0e1780 {NSUnderlyingError=0x1e0e1760 \"Broken unicode character\", NSLocalizedDescription=Expected value while parsing array}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: content\" UserInfo=0x1e0e17c0 {NSUnderlyingError=0x1e0e17a0 \"Expected value while parsing array\", NSLocalizedDescription=Object value expected for key: content}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: params\" UserInfo=0x1e0e1800 {NSUnderlyingError=0x1e0e17e0 \"Object value expected for key: content\", NSLocalizedDescription=Object value expected for key: params}",
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: request\" UserInfo=0x1e0e18d0 {NSUnderlyingError=0x1e0e1890 \"Object value expected for key: params\", NSLocalizedDescription=Object value expected for key: request}"
)

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x3397d2a3 0x3314f97f 0x338ce55f 0x339050d3 0x576c1 0x5c631 0x5d9bf 0x389a7ef5 0x388e79f1 0x388e790d 0x36bf65df 0x36bf5ccb 0x36c1e133 0x338c374d 0x36c1e593 0x36b8215d 0x33952683 0x33951ee9 0x33950cb7 0x338c3ebd 0x338c3d49 0x3462c2eb 0x36509301 0x46ab9 0x38548b20)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

现在我想知道如何在不移动到另一个 json 库的情况下解决它。 还有其他人曾经处理过包括二进制在内的json吗? 谢谢!

【问题讨论】:

  • NSString *responseStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];测试你的 json 字符串 jsonformatter.curiousconcept.com
  • 您的问题不在于客户端的 JSON 库。这是 Web 服务生成的无效 JSON 数据。
  • 那个麻烦的json来自google api...好的。没有什么可说的了。谢谢你们。我会向谷歌报告这个
  • 不幸的是,众所周知,Google API 有时会产生无效的 JSON。

标签: objective-c ios json sbjson


【解决方案1】:

来自:json.org“JSON 是一种文本格式”。 Base64 对二进制数据进行编码。

参见SO question“JSON 字符串中的二进制数据”

【讨论】:

    猜你喜欢
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    相关资源
    最近更新 更多