質問

I am trying to simply get the text displayed in the resulting page but it look like this code snipped is looking specifically for JSON only.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"userId": [loggedParent getObjectID]};
[manager POST:@"http://myurl" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
  NSLog(@"JSON: %@", responseObject);
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       NSLog(@"Error: %@", error);
   }];

This is the error I get:

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=XXXXXXXXX {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

How do I modify my code to simply read and save the text that is displayed?

役に立ちましたか?

解決

I'm assuming you're in AFNetworking 2.0, which I haven't actually used. But it looks like you should be able to modify the responseSerializer property in the AFHTTPRequestOperationManager to accept whatever content type your server is sending. AFHTTPResponseSerializer has an acceptableContentTypes field you can modify.

However, given the error you're seeing it seems like the server may be returning an "application/json" content-type but not actually delivering valid JSON content.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top