【发布时间】:2014-05-16 20:26:33
【问题描述】:
我在一个值为0 的JSON 对象中收到服务器响应。我想将此解释为FALSE 或NO,但我得到相反的结果。我究竟做错了什么?谢谢。
NSString *text=[[NSString alloc]initWithData:d.receivedData encoding:NSUTF8StringEncoding];
NSLog(@"%@", text);
self.response = [NSJSONSerialization JSONObjectWithData:d.receivedData options:kNilOptions error:nil];
NSLog(@"%@", [[self.response valueForKey:@"message"] valueForKey:@"app_version_status"]);
int temp = (int)[[self.response valueForKey:@"message"] valueForKey:@"app_version_status"];
NSLog(@"%d", temp);
NSLog(temp ? @"yes" : @"no");
这是我的控制台输出:
2014-05-16 14:18:35.819 MyApp[4410:60b] {"result":"success","message":{"app_version_status":0}}
2014-05-16 14:18:35.847 MyApp[4410:60b] 0
2014-05-16 14:18:35.847 MyApp[4410:60b] 3 //<-- What???
2014-05-16 14:18:35.847 MyApp[4410:60b] yes
【问题讨论】:
-
任何非 0 数在 C(和 Objective-C)的条件中都是“真”,因此可以丢弃该部分。然后只关注演员表 - 演员表之前的是值是多少?
-
但是服务器响应是'0'。这使它为零,对吗?
-
如果服务器响应是非零的字符“0”。
标签: objective-c json boolean