jackyshan

导航

 

afnetworking json解析出错

解决方法1

    AFURLResponseSerialization.m
258行修改

responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
responseString = [responseString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
data = [responseString dataUsingEncoding:NSUTF8StringEncoding];

解决方法2

数据请求失败  
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9b7eba0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}  
解决:  
AFNetWorking的JSON解析默认库是使用的AFJSONRequestOperation模式,只支持text/json,application/json,text/javascript,所以如果出现code=-1016错误则说明当前的JSON解析模式是text/html,所以要加上这段代码:
posted on 2016-04-16 17:57  jackyshan  阅读(663)  评论(0编辑  收藏  举报