【Objective-C】OC中id类型与NSInteger比较值

后台返回数据是NSData,转换成json字符串后如下:

{
    "value":"bf76c991995e61c5c783f3441bff4a18605bc7ba",
    "sessionId":"D72EFCCE-7836-495A-B4C6-C221573215E2",
    "status":0
}
后台返回数据

其中的status是id类型,当status的值为0时,说明返回的value是正确的。那么问题来了,怎么比较id类型和NSInteger类型的值是否相等呢?

// 截个图
    [[STNetworkManager sharedManager] getWithUrl:@"http://169.254.226.58:8100/screenshot" success:^(NSData *data) {
        NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSDictionary *dict = [NSDictionary pf_dictionaryWithJsonString:jsonStr];
        
        NSNumber *statusNumber = dict[@"status"];
        
        if (statusNumber.integerValue == 0) {
            NSString *imgStr = [dict valueForKey:@"value"];
            NSDictionary *parameterDict = @{@"x":@"100",
                                           @"y":@"350",
                                           @"event":@"click",
                                           @"message":@"",
                                           @"imageUrl":imgStr,
                                           @"resolution":@"",
                                           @"systemType":@"IOS",
                                           @"model":@"6s Plus",
                                           @"brand":@"Apple",
                                           @"devicename":@"bf76c991995e61c5c783f3441bff4a18605bc7ba",
                                           @"mac":@"78:7b:8a:c0:57:f8"};
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameterDict options:NSJSONWritingPrettyPrinted error:nil];
            NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
            
            [self sendMessage:[jsonStr stringByAppendingString:@"\n"]];
            
        } else {
            NSLog(@"截图失败");
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@", error);
    }];

你可能感兴趣的:(【Objective-C】OC中id类型与NSInteger比较值)