解析JSON响应。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { response=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];} 

在这里,我得到“响应值”中的响应 – > [{"response":true,"danger":false}]

问题是:如何将“危险”(真/假)拯救到新变量中以便在其他方法中使用它? 我需要知道“危险”是真是假是因为如果它是真的,我必须表现出警觉。

我真的很感激有人的帮助,因为我被困在这里。

使用NSJSONSerialization: http : //developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html

 NSArray *jsonArray=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; BOOL danger=[(NSNumber*)[(NSDictionary*)[jsonArray objectAtIndex:0] objectForKey:@"danger"] boolValue];