ios – AFNetworking 2.0和响应序列化选项

ios – AFNetworking 2.0和响应序列化选项,第1张

概述一旦我触发对 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 {NSDebug 一旦我触发对 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 OKServer: Microsoft-IIS/7.0X-Powered-By: ASP.NETContent-Type: application/Json;charset=utf-8X-AspNetMvc-Version: 3.0Connection: closeDate: Mon,28 Oct 2013 20:02:21 GMTContent-Length: 121Cache-Control: privateX-AspNet-Version: 4.0.30319[{"StoryID":1,"IsFeatured":true}]
解决方法 您需要使用serializerWithReadingOptions创建自己的AFJsONResponseSerializer实例:并配置您的系统以使用它(代替默认的JsON响应序列化程序). 总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1104768.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存