1
votes

I am facing some problem in parsing JSON using AFNetworking 2.0. It always executes the failure block when a new line character comes with response data.

My Code -

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer           = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

[manager GET:@"http://mobile.MYSERVICENAME/outbox.aspx?u=SONALI2547&p=25472870&sender=sjssgn" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
{
    NSLog(@"%@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
    NSLog(@"%@", error);
}];

ERROR -

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unescaped control character around character 512.) UserInfo=0xa279660 {NSDebugDescription=Unescaped control character around character 512.}

enter image description here I am check I am check my url on jsonlint it give me above error.

1
Does jsonlint.com say your JSON is valid? What is the control character?Wain
@wain when new line comes then it show invalid json but same url is running fine in browser and With JSONParsing without AFNetworking only problem occurs when i'm using AFNetworking2.0.Ravikant
The easiest way to get more information is to take the response data (as it comes in as a sequence of bytes, aka a NSData object), create a NSString from it (e.g. [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]) and print that string to the console. Then inspect character at index 512. Note: unescaped control chars are not allowed in a decoded JSON representing a source string.CouchDeveloper
I am not getting NSData coz my control not goes in success block.Ravikant
Does anyone have an update on this ? I'm facing the same issue.Nishan29

1 Answers

0
votes

I had the same problem. The problem is probably related with the way of the encoding and the decoding of the serve. Replace "\n" to "\n" in your JSON, then it will be fine.