iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be comple

iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be comple,第1张

概述Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unescaped control character around character 1419.) UserInfo=0x1563cdd0 {NSDebugDescription=Unesca

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

}

总结

以上是内存溢出为你收集整理的iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be comple全部内容,希望文章能够帮你解决iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be comple所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1053027.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存