Jak tylko wywoła żądanie do zasobu JSON otrzymuję następujący:AFNetworking 2.0 i odpowiedź opcje serializacji
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.}
problem polega na tym, gdzie należy ustawić pozwalają fragmenty w AFNetworking 2.0?
UPDATE:
Moja klasa to klasa sub AFHTTPSessionManager. Mam już utworzony JSONResponseSerializer i również nie działa.
JSON zwracane jest w następujący sposób:
[{"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;
}
Błąd zwracany jest następujący:
[0] (null) @"NSDebugDescription" : @"Invalid value around character 0."
odpowiedź z serwera WWW:
[{"StoryId":1,"Title":"The big red dog","Abstract":"There was a big red dog and the dog was very big","IsFeatured":true}]
RESPONSE status z SERWER WWW:
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}]
To jest problem z odpowiedzią serwera WWW, ** nie ** z AFNetworking. – akashivskyy
Odpowiedź jest ważna! Właśnie sprawdziłem poprawność JSON i przywracano prawidłowy JSON. –
Nie powiedziałem, że to * jest nieprawidłowe *. Powiedziałem, że * problem jest spowodowany przez *. Dane JSON są zwykle zawarte w tablicy lub obiekcie. @Wain ma rację, musisz powiedzieć AFNetworking, które opcje powinny używać 'NSJSONSerialization', aby odczytać dane JSON. – akashivskyy