我正在尝试检查 JSON 值是“开”还是“关”,然后对其执行操作:
-(IBAction)turnon {
NSURL *api = [NSURL URLWithString:@"http://app-content.co.uk/api/example.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:api];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.getinfo = [JSON objectForKey:@"data"];
NSLog(@"Rapid reply: %@", JSON);
} failure:nil];
NSDictionary *getDB= [self.getinfo objectAtIndex:0];
[operation start];
if([[getDB objectForKey:@"50min_1"] isEqualToString:@"on"])
{
NSLog(@"Works");
}
else {
NSLog(@"Doesn't work");
}
}
我的 JSON 文件如下所示:
{
"data": [
{
"50min_1": "on",
"50min_2": "on",
"50min_3": "on",
"50min_4": "on",
"50min_5": "on",
"50min_6": "on",
"50min_7": "on",
"50min_8": "on"
}
]
}
如果我这么说,一切看起来都很好,但是 NSLog 总是报告“不起作用”,这意味着它没有从 JSON 文件中获得正确的值,尽管服务器有值。
NSLog(@"Rapid reply: %@", JSON);
按应有的方式回复 JSON 文件。我错过了什么?