afnetworking NSCocoaErrorDomain Code=3840 解决

afnetworking json解析出错

解决方法1

    AFURLResponseSerialization.m
258行修改

responseString = [responseString stringByReplacingOccurrencesOfString:@"
" withString:@""];
responseString = [responseString stringByReplacingOccurrencesOfString:@"
" withString:@""];
responseString = [responseString stringByReplacingOccurrencesOfString:@"	" 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,所以要加上这段代码:
原文地址:https://www.cnblogs.com/jackyshan/p/5398958.html