我需要检查我的值是否包含“false”或字符串。iOS,JSON检查值是否为假或字符串
JSON:
{"success":true,"name":[{"image":false},{"image":"https:\/\/www.url.com\/image.png"}]}
我的代码:
NSData *contentData = [[NSData alloc] initWithContentsOfURL:url];
NSDictionary *content = [NSJSONSerialization JSONObjectWithData:contentData options:NSJSONReadingMutableContainers error:&error];
的NSLog显示我用于第一图像值:
NSLog(@"%@", content);
图像= 0;
我有一个UICollectionView,我想从URL设置图像。 如果值“图像”是错误的,我想把其他图像,但我不知道如何检查它是否是假的。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if ([[[content objectForKey:@"name"] objectAtIndex:indexPath.row] objectForKey:@"image"] == nil)
我也试过“== false”“== 0”,但没有任何工作。
任何人有想法?
“false”(当不用引号括起来)作为一个NSNumber编码一个零值。 –