値が存在する場合、objectAtIndex を実行するだけで問題が発生します。
私のコード:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSDictionary *results = [json objectForKey:@"d"];
NSString *error = [results objectForKey:@"error"];
NSLog(@"results::%@", [results objectForKey:@"agency"]);
if ( results !=nil)
{
item = [[results objectForKey:@"agency"] objectAtIndex:0];
codeItem = [[results objectForKey:@"agency"] objectAtIndex:1];
}
json にデータがある場合は正常に動作しますが、json が次のように返される場合:
{"d":{"success":true,"agency":[]}}
クラッシュします。if ステートメントが間違っていることはわかっていますが、これを機能させる正しい方法はわかりません。