0

My app is crashing when there is no internet. This is because

NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData
                                                               options:NSJSONReadingMutableContainers error:&error];

returns the error 'data parameter is nil'.

How can I prevent this from crashing as I am caching the jsonData using SDWebImage. So it should still be there even if there is no internet!

0

2 Answers 2

7

You can make sure that the code is executed just if the data is not nil:

if (jsonData) {
    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData
                                                               options:NSJSONReadingMutableContainers error:&error];
}
0

not handle only nil , and not proper format of json too and you can get the error msg for further

  @try {

        responseDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    }
    @catch (NSException *exception) {
        NSLog(@"exception %@",exception);
    }
1
  • 1
    please add your comment to the answer - code only answers are discouraged here!
    – Blitz
    May 23, 2014 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.