Try this
NSError *error = nil;
NSArray *theArray = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
if (!theArray) { // DO THIS CHECK
NSLog(@"error: %@", error);
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Data failed to load."
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:@"Retry",nil];
[message show];
}
else
{
NSLog(@"parsed data");
NSDictionary *dict0 = [theArray objectAtIndex:147];
}
If any error occurs while getting json
from NSData
then it will be recorded in object of NSError
. So if this object is nil means there is no error while parsing json, and if that object holds value means there is some issue while parsing.