iOS – NSJSONSerialization:无法将数据转换为字符串周围的字符
发布时间:2020-12-14 19:00:49 所属栏目:百科 来源:网络整理
导读:我在解析 JSON时收到此错误: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:error];Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error
我在解析
JSON时收到此错误:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unable to convert data to string around character 73053.) UserInfo=0x1d5d8250 {NSDebugDescription=Unable to convert data to string around character 73053.} 有任何建议如何解决这个问题? 添加 解决方法
检查您正在解析的数据是否实际上是有效的JSON(而不仅仅是’几乎’JSON).当您有不同的数据格式无法解析为JSON时,就会发生该错误.参见例如:
iOS 5 JSON Parsing Results in Cocoa Error 3840 你的JSON中也有一个顶级容器吗?数组或字典.例: { "response" : "Success" } 更新 JSON的默认编码是UTF-8.特殊/异国情调的字符不是UTF-8的问题,但请确保您的服务器正确地将其内容正确编码为UTF-8.另外,你有什么要告诉你的JSON解释器使用不同的编码吗? 如果您的JSON来自Web服务,请将URL放入此页面以查看有关编码的内容: http://validator.w3.org/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |