IOS json 解析遇到错误问题解决办法
2017-01-17 08:55
981 查看
概要:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (Unescaped control character around character 1419.) UserInfo=0x1563cdd0 {NSDebugDescription=Unescaped control character around character 1419.}
之前解析json的时候都是标准格式,json数据当中没有 \n \r \t 等制表符。
今天在解析的时候发现json解析时好时坏,用在线json解析也米有问题。找了半天终于发现是制表符在作怪,由于标准的json解析是不允许有这几个制表符的。所以在收到保温的时候我们需要把这几个制表符给过滤掉。
NSString * responseString = [request responseString]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\t" withString:@""]; NSLog(@"responseString = %@",responseString); SBJsonParser *parser = [[[SBJsonParser alloc]init] autorelease]; id returnObject = [parser objectWithString:responseString]; NSDictionary *userInfo = nil; NSArray *userArr = nil; if ([returnObject isKindOfClass:[NSDictionary class]]) { if (userInfo) { [userArr release]; } userInfo = (NSDictionary*)returnObject; } else if ([returnObject isKindOfClass:[NSArray class]]) { userArr = (NSArray*)returnObject; } NSError* e = nil;
//系统自带的解析方式。
NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&e]; if (e) { NSLog(@"%@",e); }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- 有关使用cJSON包解析或者创建JSON时遇到的错误和解决办法
- IE6中运行EXTJS中某些组件无法解析DOMINO产生的JSON数据问题的解决办法
- 遇到的问题------SQL Server 附加数据库失败的解决办法(3415错误)
- DELPHI XE5 UP2 运行IOS 遇到 Wrapper init failed: (null)问题的解决办法
- 升级到Xcode 5.1和iOS 7遇到的各种问题及解决办法汇总:
- 使用Gson解析Json数组遇到的泛型类型擦除问题解决方法
- 遇到的问题------SQL Server 附加数据库失败的解决办法(3415错误)
- IIS5 HTTP500内部错误,asp 不能解析解决办法 (问题2)(转)
- ios 真机调试遇到的错误: ld: symbol(s) not found for architecture arm64的解决办法
- 解决android使用gson解析json字符串,并使用混淆编译方式打包apk遇到的问题
- sbjson解析json数据遇到JSONValue failed. Error is: Illegal start of token [Ô]解决办法
- EXP-00056遇到Oracle错误1455问题解决办法
- Windows Live Message (MSN) 登陆错误解决办法 -- windows live communications platform 遇到问题需要关闭
- ios 真机调试遇到的错误: ld: symbol(s) not found for architecture arm64的解决办法
- 遇到错误-----安装DBD:MySql模块遇到的问题及解决办法Can't exec "mysql_config": 没有那个文件或目录 at Makefile.PL line 479.
- ios升级为5后,程序编译时遇到的关于libz 1.2.3.dylib类包的各种问题解决办法
- X File 解析中遇到的问题和最终解决办法
- 升级到Xcode 5.1和iOS 7遇到的各种问题及解决办法汇总:
- 在解析json时遇到get(key);key不存在时解析错误的问题
- IIS5 HTTP500内部错误,asp 不能解析解决办法(问题1)(转)