gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:10:14 24 4
gpt4 key购买 nike

一旦我触发对 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."

来自网络服务器的响应:

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

来自网络服务器的响应状态:

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,"Title":"The big red dog","Abstract":"There was a big red dog and the dog was very big","IsFeatured":true}]

最佳答案

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

关于ios - AFNetworking 2.0 和响应序列化选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19643576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com