如何检查iphone中已解析元素的条件

| 从我项目中的Json解析中,我正在获取这些元素... 执行指令:
NSArray *feed3 = (NSArray *)[feed valueForKey:@\"type\"];  
NSLog(@\" %@\",feed3);
在控制台我得到这个 ( 状态, 照片, 链接, 视频 ) 现在,我要检查这些元素的条件。 喜欢
if(type==staus){  
//do some thing  
} 
如何在xcode中做到这一点?
已邀请:
我假设
feed3
是解析另一个问题中列出的JSON数据后JSON解析器返回的对象。在这种情况下:
* the top level object is an array
* every element in the array is an object/dictionary representing news
* this object/dictionary contains the following keys:
  * application (object/dictionary with two keys: id, name)
    * id (number)
    * name (string)
  * created_time (string)
  * from (object/dictionary with two keys: id, name)
    * id (number)
    * name (string)
  * icon (string)
  * id (string)
  * likes (object/dictionary with two keys: count, data)
    * count (number)
    * data (array)
      * every element in the array is an object/dictionary
      * this object/dictionary has two keys (id, name)
        * id (number)
        * name (string)
  * link (string)
  * name (string)
  * picture (string)
  * properties (array of objects/dictionaries)
  * type (string)
  * updated_time (string)
解析JSON数据时,了解数据的组织方式至关重要。我建议您在必须解析JSON时始终执行上述操作。 由于您对“类型”感兴趣,因此需要遵循以下路径: 遍历新闻的顶层 数组中的每个元素都是一个对象/字典 该对象/词典的键名为“类型” 以下代码可以解决问题:
for (NSDictionary *news in feed3) {
    NSString *type = [news objectForKey:@\"type\"];

    if ([type isEqualToString:@\"status\"]) {
       …
    }
    else if ([type isEqualToString:@\"photo\"]) { 
       …
    }
    else if ([type isEqualToString:@\"link\"]) { 
       …
    }
    else if ([type isEqualToString:@\"video\"]) { 
       …
    }
}
请注意,通常应使用
-objectForKey:
代替
-valueForKey:
-objectForKey:
是在
NSDictionary
中声明的方法,它用于在给定相应键的情况下获取存储在字典中的对象。
-valueForKey:
是KVC方法,并具有其他目的。特别是,当您不期望一个数组时,它可以返回一个数组!
检查下面
for(int index = 0 ; index < [feed3 count] ; index++)
{
    NSString* tempString = [feed3 objectAtIndex:index];

    if([tempString isEqualToString:@\"status\"]) 
    {
      //Get value for status from value array
    }
    else if([tempString isEqualToString:@\"photo\"]) 
    {
      //Get value for photo from value array
    }
    else if([tempString isEqualToString:@\"link\"]) 
    {
      //Get value for link from value array
    }
    else if([tempString isEqualToString:@\"video\"]) 
    {
      //Get value for video from value array
    }
}

要回复问题请先登录注册