HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – AFNetworking 2.0和响应序列化选项大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一旦我触发对 JSON资源的请求,我就会得到以下信息:
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=0x1d87a2c0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

问题是我应该在哪里设置AFNetworking 2.0中的允许片段?

更新:

我的类是AFhttpSessionManager的子类.我已经创建了一个JSONResponseserializer,它也不起作用.

返回的JSON如下:

[{"StoryId":1,"title":"The big red dog","Abstract":"There was a big red dog and the dog was very big","IsFeatured":truE}]

-(instanCETypE) initWithBaseURL:(NSURL *)url
{
    NSURL *base = [NSURL URLWithString:@"URL to the web service that returns the json"];
    self = [super initWithBaseURL:base];

    AFJSONResponseserializer *responseserializer = [AFJSONResponseserializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

    [self setResponseserializer:responseserializer];

    return self;
}

返回的错误如下:

[0] (null)  @"NSDebugDescription" : @"Invalid value around character 0."

来自WEB服务器的响应:

[{"StoryId":1,"IsFeatured":truE}]

来自WEB服务器的响应状态:

http/1.1 200 OK
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Content-Type: application/json;charset=utf-8
X-AspNetMvc-Version: 3.0
Connection: close
Date: Mon,28 Oct 2013 20:02:21 GMT
Content-Length: 121
Cache-Control: private
X-AspNet-Version: 4.0.30319

[{"StoryId":1,"IsFeatured":truE}]

@L_801_4@

您需要使用serializerWithReadingOptions创建自己的AFJSONResponseserializer实例:并配置您的系统以使用它(代替认的JSON响应序列化程序).

大佬总结

以上是大佬教程为你收集整理的ios – AFNetworking 2.0和响应序列化选项全部内容,希望文章能够帮你解决ios – AFNetworking 2.0和响应序列化选项所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。