使用AFNetworking 报错提示
使用AFNetworking 框架 解析数据 报错提示
数据请求失败
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,所以要加上这段代码:
[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(@"数据请求失败%@",error);
}];
[jsonOperation start];
让他支持text/html模式就可以解决了
数据请求失败
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.}
解决:
后台返回的不是一个有效的JSON string 所以库里面转化的时候一个error就抛出了
使用AFNetworking 报错提示的更多相关文章
- eclipse里maven install时,报错提示jdk为无效的目标版本:1.7
http://blog.csdn.net/wabiaozia/article/details/51733372 ************************************ 报错提示: [ ...
- appium---【已解决】【Mac】from appium import webdriver报错提示“Unresolved import webdriver”
报错提示: from appium import webdriver提示Unresolved import webdriver 报错原因:没有安装Appium_Python_Client 解决办法: ...
- VS发布网站时,报错提示:“未能将文件xxx复制到xxx,未能找到文件xx”三种解决方案!
发布网站时候大家可能会遇到这样的情况,就是报错提示说:“未能将文件xxx复制到xxx,未能找到文件xx”,这个问题一般来说有三种解决方案,个人倾向第三种,如图: 解决方案如下: 方案一.把系统提示缺失 ...
- oracle dg 报错提示 涉及硬盘错误
###oracle dg 报错提示 涉及硬盘错误 Dec 23 03:28:01 xhisdg rsyslogd: [origin software="rsyslogd" swVe ...
- linux git 报错提示 fatal: 'origin' does not appear to be a git repository 解决办法
输入: git pull origin master git报错提示 fatal: 'origin' does not appear to be a git repository fatal: Cou ...
- Element和vue框架报错提示
上面报错提示Error in render function: "TypeError:Cannot read property '$options' of undefined" 就 ...
- oracle 可以连接数据库,vs连不上. 报错提示:ORA-12154: TNS: 无法解析指定的连接标识符
方法1:问题:VS 连接 Data Source=ORCL_Service19;User Id=*;Password=* 连接不上 oracle 可以连接数据库,vs连不上,报错提示:ORA-1215 ...
- 关于编辑器对<input>标签报错提示“表单输入没有相关label”的问题
相信很多朋友在制作表单的时候,我们的编辑器会有下图的相关提示吧 我们发现虽然这样并不影响我们的正常使用,但是看着这样的报错提示总是很让人心烦,那么这到底是为什么呢? 其实,这是因为编辑器建议我们在使用 ...
- mac下连接本地安装的mysql报错提示密码过期
前提: mac中之前安装了mysql,一段时间没使用,今天使用mysql客户端去连接,报错提示密码过期,原因是mysql5.7之后版本有密码过期这个功能. error: Your password h ...
随机推荐
- Oracle本地,远程,分布式登录
identify认证,确定; identity同一性,个性; 本地连接 sqlplus scott/tiger@localhost:1521/orcl 这句话就等于sqlplus scott/tige ...
- use worker without js file
var blob = new Blob(['onmessage=function(e){postMessage(e.data);}']); debugger; // Obtain a blob URL ...
- 网站开启Gzip压缩-apache
找到并打开apache/conf目录中的httpd.conf文件 httpd.conf中打开deflate_Module和headers_Module模块,具体做法为将 如下两句前面的#去掉: Loa ...
- zoj 3716
题目给我们四个点,要求我们以这四个点为圆心,形成四个相切的圆: 求他们的半径和: 首先我们从他们中间选出三个点,以这三个点为圆心的三个圆最大可以两两互相相切: 证明:假设这三个圆的半径分别为a,b,c ...
- 严重: The web application [] registered the JDBC driver 错误
近日发现启动tomcat的时候报如下警告: -- :: org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 严重: The ...
- Delphi捕捉DLL执行所抛出的异常。
先来说一下我如何写我的Dll文件的. 先看代码: 代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://w ...
- 【Xamarin挖墙脚系列:现有IPhone/IPad 设备尺寸】
原文:[Xamarin挖墙脚系列:现有IPhone/IPad 设备尺寸]
- 解析rss和atom文件出现乱码问题
try { String xmlString = new String(response.data, Charset.forName("UTF-8")); XmlPullParse ...
- [Quick-x]移动CCEditbox的父对象导致输入框位置偏移问题
CCEditbox对象添加到某个layer,当layer移动时候,editbox输入状态下输入光标保持在原位,看起来就是光标发生了偏移 如果开始时添加的editbox不在屏幕内的话,光标会出现在屏幕边 ...
- Atom 扩展离线安装
1.下载原始包 2.解压放入atom的packages文件夹中 3.通过nodejs的npm指令进行安装 运行->cmd 4.重启Atom就ok了