最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
IOS json 解析遇到错误问题解决办法
时间:2022-06-25 23:31:17 编辑:袖梨 来源:一聚教程网
概要:
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:@"rn"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:[NSDictionaryclass]]) {
if(userInfo) {
[userArr release];
}
userInfo = (NSDictionary*)returnObject;
}
elseif([returnObject isKindOfClass:[NSArrayclass]]) {
userArr = (NSArray*)returnObject;
}
NSError* e = nil; //系统自带的解析方式。 NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&e];
if(e) {
NSLog(@"%@",e);
} |
相关文章
- 《女神异闻录:夜幕魅影》厄抑异象之境有哪些玩法 06-16
- 最火币圈十大全球交易所现货交易TOP10-去中心化币圈交易所币安交易所推荐 06-16
- 《无限暖暖》我是愿望神给我噗灵任务达成技巧总结 06-16
- 如何获取SOLX币?2025OKX交易所简单教程 06-16
- SNORT币支持跨境支付吗-2025币安交易所潜力分析 06-16
- 《道友请留步》冬傲雪新变装图片及获得方法有哪些 06-16