You need to code more securely, and you need to report bugs as they are found.
First, check to see if the JSON session has figured out, and if so, report an error:
NSData *data1 = [jsonResponse1 dataUsingEncoding:NSUTF8StringEncoding]; jsonArray = [NSJSONSerialization JSONObjectWithData:data1 options:kNilOptions error:&err]; if (jsonArray == nil) { NSLog(@"Failed to parse JSON: %@", [err localizedDescription]); return; }
Secondly, if these keys are not in JSON, objectForKey: will return nil , and when you try to add this to arrays, it will throw an exception, which you want to avoid:
for (NSDictionary *json in jsonArray) { NSString * value = [json objectForKey:@"van"]; if (value != nil) { [self.van addObject:value]; lbl1.text = value; } else { NSLog(@"No 'van' key in JSON"); } NSString * value1 = [json objectForKey:@"vuan"]; if (value1 != nil) { [self.vuan addObject:value1]; lbl4.text = value1; } else { NSLog(@"No 'vuan' key in JSON"); } }
So, in short: runtime errors will occur, so you need to ensure that they are handled. When they happen, you need to give as much information as possible about them so that you can diagnose and correct them.
source share