使用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 ...
随机推荐
- <三> SQL杂七杂八
批量插入测试数据 use Testdeclare @count INTset @count = 0while(@count < 10)begin waitfor delay '000:00:10 ...
- Java 单链表逆序
代码: package com.wangzhu.linkedlist; public class LinkedListDemo { /** * @param args */ public static ...
- 很受欢迎的Linux笔记(短小精悍)
http://blog.csdn.net/xsl1990/article/details/8274028 如何知道所使用的LINUX是哪个发行版? lsb_release -a 查找某个文件的另类方法 ...
- 乐1/MACBOOK/ N1 Type-C接口新体验
经过在华强北电子市场排队一个小时,笔者顺利买到了期待已久的乐1,结合之前的NOKIA平板电脑N1,苹果全新MACBOOK,终于集齐了手机.平板.笔记本电脑三种TYPE-C接口设备(能兑换极品装备吗?^ ...
- is present but cannot be translated into a null value due to being declared as a primitive type
解决办法:把基本类型改为对象,譬如此处将pageId的类型由int 改为Integer 2016-10-19 19:36:11.275 DEBUG [http-nio-9999-exec-2][org ...
- java数组或集合返回空的问题
在有返回值的情况下,平时我写代码基本遇到错误什么都是返回null,我因为我觉得把数组或集合这个初始化占空间. 但是我发现这样在每次客户段调用都要进行非空判断,而且有时调用内置api还容易报错误,于是解 ...
- 近期会放出tlplayer for android的更新版本
tlplayer for android的一次重大更新在近期将会放出,自从去年初的时候放出tlplayer android版本后,一直都没有更新tlplayer,而tlplayer for windo ...
- Pizza pieces
Pizza pieces Description In her trip to Italy, Elizabeth Gilbert made it her duty to eat perfect piz ...
- 卸载Visual Studio Code后删除右键Open with Code…
Win+R,输入 regedit ,点击确认,进入注册表编辑器 Ctrl+F,搜索 Ticino ,将搜索出来的Ticino都删除就行了
- php include include_once require require_once 的区别与联系
一.require 与 include 的区别: The require() function is identical to include(), except that it handles er ...