IOSjson解析遇到错误问题解决办法

概要:

成都创新互联是由多位在大型网络公司、广告设计公司的优秀设计人员和策划人员组成的一个具有丰富经验的团队,其中包括网站策划、网页美工、网站程序员、网页设计师、平面广告设计师、网络营销人员及形象策划。承接:成都网站建设、网站制作、网站改版、网页设计制作、网站建设与维护、网络推广、数据库开发,以高性价比制作企业网站、行业门户平台等全方位的服务。

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);

}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

当前标题:IOSjson解析遇到错误问题解决办法
网页URL:https://www.cdcxhl.com/article4/ghoeoe.html

成都网站建设公司_创新互联,为您提供电子商务自适应网站网站设计域名注册网站收录网站策划

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司