使用AFNetworking 报错提示
?
使用AFNetworking 框架 解析數(shù)據(jù) 報(bào)錯(cuò)提示
數(shù)據(jù)請(qǐng)求失敗
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解析默認(rèn)庫(kù)是使用的AFJSONRequestOperation模式,只支持text/json,application/json,text/javascript,所以如果出現(xiàn)code=-1016錯(cuò)誤則說(shuō)明當(dāng)前的JSON解析模式是text/html,所以要加上這段代碼:
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];//加上這句話
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",kDMBaseURL]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];//加上這句話
AFJSONRequestOperation *jsonOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
DMLog(@"str %@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
DMLog(@"數(shù)據(jù)請(qǐng)求失敗%@",error);
}];
[jsonOperation start];
讓他支持text/html模式就可以解決了
?
?
數(shù)據(jù)請(qǐng)求失敗
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=0x9ba1b30 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
解決:
后臺(tái)返回的不是一個(gè)有效的JSON string 所以庫(kù)里面轉(zhuǎn)化的時(shí)候一個(gè)error就拋出了
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/yjg2014/p/3821679.html
總結(jié)
以上是生活随笔為你收集整理的使用AFNetworking 报错提示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Android中的ContentValu
- 下一篇: offset说明