JSON 解析错误
我在 iOS 上使用 SBJson 框架(也称为 json-framework)。
解析某个 JSON 文件时,出现以下错误: -JSONValue 失败。错误是:未转义的控制字符 [0x09]'
我已经多次使用这个框架,并且还在同一个应用程序中解析一个非常相似的 JSON 文件(甚至更长),并且它工作正常。
我尝试扔掉一堆 NSLogs,一切似乎都很好。有人可以告诉我这个错误意味着什么,或者至少如何继续调试这样的错误吗?
以下是显示错误的代码:
- (void)downloadSchedule:(NSString *)jsonString {
// Get JSON feed URL and instantiate a dictionary object with its content
NSDictionary *topDic = [jsonString JSONValue];
NSLog(@"topDic count %d", [topDic count]);
topDic 显示计数为 0。错误位于 [jsonString JSONValue]
行。
谢谢
I am using SBJson framework (also known as json-framework) for the iOS.
When parsing a certain JSON file, I am getting the following error:
-JSONValue failed. Error is: Unescaped control character [0x09]'
I have used this framework many times and I am also parsing a very similar JSON file (that is even much longer) in that same app and it's working fine.
I tried throwing around a bunch of NSLogs and everything seems to be fine. Can someone please point me to what this error means, or at least how to go ahead in debugging such an error?
Here is the code that displays the error:
- (void)downloadSchedule:(NSString *)jsonString {
// Get JSON feed URL and instantiate a dictionary object with its content
NSDictionary *topDic = [jsonString JSONValue];
NSLog(@"topDic count %d", [topDic count]);
topDic is showing a count of 0. The error is at the [jsonString JSONValue]
line.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有一个很好的解决方案。应用此方法删除转义字符。
通过像这样传递输出字符串来调用此方法
I have a great solution for it. Apply this method for remove escaped characters.
Call this method with passing your output string like this
我猜您的文件包含一个未编码的选项卡 (ascii
0x09
),根据 json 语法。I guess your file contain an unencoded tab (ascii
0x09
) that should be replaced with\t
according to the json grammar.看一下 http://www.json.org/ 有一些字符需要转义可以被 JSON 正确解析。这就是原因。该文件不是正确的 JSON。
Have a look at http://www.json.org/ There are some characters that need to be escaped to be properly parsed by JSON. This is the cause. The file is not proper JSON.
如果你的文件有 '\n' 或 '\r' 类型的 html qoutes 那么它可能会导致 obj-c 错误。
您可以添加:
[jsonString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"
"]
我遇到了同样的问题并使用此解决了。
If your file is having '\n' or '\r' kind of html qoutes then it may cause error in obj-c.
You can add :
[jsonString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br />"]
I was having same problem and solved using this.