我无法检查我的其中一个 key 是否为空。
以下是我正在处理的已解析 JSON 响应:
案例一(key 'tags' 不为空)
{
height = 480;
pid = "a@bsioihf93u420934";
tags = (
{
attributes = {
mood = {
confidence = 42;
value = happy;
};
smiling = {
confidence = 52;
value = false;
};
};
center = {
x = "49.86";
y = "60.52";
};
confirmed = 0;
width = "50.28";
}
);
url = "http://abc/efg/hijk/lmnop.jpg";
width = 360;
}
有时响应如下所示:
情况 2(键 'tags' 为空)
{
height = 480;
pid = "a@bsioihf93u420934";
tags = (
);
url = "http://abc/efg/hijk/lmnop.jpg";
width = 360;
}
当我在情况 2 中检查 'tags' 是否为空时,它返回 false :
if ([photo objectForKey:@"tags"] == nil)
检查日志中 [photo objectForKey:@"tags"]
的实际值返回:
(
)
我还能如何检查“标签”是否为空?
最佳答案
尝试:
if ([[photo objectForKey:@"tags"] count] == 0)
关于objective-c - 检查复杂 JSON 响应中的空键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11489201/