我在app上有一个现有的应用程序,它突然开发了一些与I 7.1更新相关的问题。这是一个我不能让我的头,虽然,它似乎应该(和过去)工作。我试图检查JSON字符串的“成功”键是否等于'1‘。
AFJSONRequestOperation *op = [AFJSONRequestOperation JSONRequestOperationWithRequest:req success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
if ([[JSON objectForKey:@"Success"] isEqualToValue:[NSNumber numberWithInt:1]]) {
// succeeded
NSLog(@"Reached success while submitting");
} else {
NSLog(@"JSON: %@", [JSON objectForKey:@"Success"]);
// Success was not 0
}
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
// parse/download error
}];即使成功键为1,程序始终会到达else语句。
Printing description of JSON:
{
EntryId = 5235;
EntryLink = "https://cpdme.wufoo.com/api/v3/forms/z7x4a9/entries.json?Filter1=EntryId+Is_equal_to+5235";
Success = 1;
}发布于 2014-03-27 12:07:56
考虑将代码更改为:
NSNumber *statusValue = [JSON objectForKey:@"Success"];
if ([statusValue boolValue]) {
...因为这有一个更广泛的范围,以正确识别真相。它还将悄悄地处理作为字符串实例的值。
我猜您当前的代码在比较过程中遇到了类类型不匹配的问题。记录[JSON objectForKey:@"Success"]和[NSNumber numberWithInt:1]的类和内容以验证结果。
https://stackoverflow.com/questions/22686883
复制相似问题