美文网首页
【Objective-C】OC中id类型与NSInteger比较

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

作者: 悄然林静 | 来源:发表于2019-01-17 13:59 被阅读0次

    后台返回数据是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比较

          本文链接:https://www.haomeiwen.com/subject/aehmiftx.html