- (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];
关于ios - 解析 JSON 响应。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11343567/