gpt4 book ai didi

iphone - 如何检查数组中的值是否不为 NULL?

转载 作者:可可西里 更新时间:2023-11-01 06:19:21 26 4
gpt4 key购买 nike

所以我正在解析 Twitter 时间线。 JSON 响应中有一个名为“following”的字段。应该是真还是假。

但有时字段会丢失。

当我这样做时:

NSLog(@"%@", [[[timeline objectAtIndex:i] objectForKey:@"user"] objectForKey:@"following"]);

这是输出:

1
1
0
0
1
<null>
1
1

那么如何检查这些值呢?

最佳答案

NSArray 和其他集合不能将 nil 作为值,因为 nil 是集合结束时的“标记值”。您可以使用以下方法查找对象是否为空:

if (myObject == [NSNull null]) {
// do something because the object is null
}

关于iphone - 如何检查数组中的值是否不为 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10077324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com