日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用AFNetworking 报错提示

發(fā)布時(shí)間:2024/4/17 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用AFNetworking 报错提示 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

使用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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。