Sunday, 1 September 2013

Ok in simulator but throwing exception in ios device

Ok in simulator but throwing exception in ios device

when i am running my app in the simulator everything is working perfectly
.But when i running the same app in the Ipad exception is being thrown.
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'data parameter is nil. In my app at one step i have to request a
web-URl and need to parsed the returned JSON response. But I have checked
the web-url and have been able to parse perfectly in simulator. But all
the problem has been arisen in real ios device.But I think i have
identified the code where it is getting wrong.
+ (NSDictionary*) getParsedJSON:(NSString*) urlString {
NSLog(@"################################################################################");
NSLog(@"getParsedJSON => urlString:");
NSLog(@"%@", urlString);
NSURL* url = [NSURL URLWithString:urlString];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
NSURLResponse *response1 = nil;
NSError *error = nil;
NSData* response = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response1 error:&error];
//NSData* response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSLog(@"--------------------------------------------------------------------------------");
NSString* responseString = [[NSString alloc] initWithData:response
encoding:NSUTF8StringEncoding];
NSLog(@"getParsedJSON => responseString:\n%@", responseString);
NSLog(@"--------------------------------------------------------------------------------");
NSError* jsonParsingError = nil;
NSDictionary* parsedJSON = [NSJSONSerialization
JSONObjectWithData:response options:0 error:&jsonParsingError]; // here is
place where exception seems to be thrown.
if (jsonParsingError) {
NSLog(@"ERROR in parsing JSON: %@", jsonParsingError);
} else {
NSLog(@"getParsedJSON => parsedJSON: \n%@", [parsedJSON description]);
}
NSLog(@"################################################################################");
return parsedJSON;
}
I have identified the line where it seems to be wrong .I have also
attached screen shot of the exception report..Hoping for your experienced
reply.

No comments:

Post a Comment