2011-01-23 144 views
0

我有一个NSDictionary像访问的NSDictionary内容

{ 
     nodeAttributeArray =   (
         { 
       attributeName = ReportDate; 
       nodeContent = "08-31-1986"; 
      }, 
         { 
       attributeName = ReportType; 
       nodeContent = PQ1; 
      } 
     ); 
     nodeName = Period; 
    }, 
    { 
     nodeAttributeArray =   (
         { 
       attributeName = ReportDate; 
       nodeContent = "08-31-1987"; 
      }, 
         { 
       attributeName = ReportType; 
       nodeContent = PQ2; 
      } 
     ); 
     nodeName = Period; 
    } 

我在这里示出的2个值。但是我的代码里面几乎有50个这样的成员 如何访问for循环中的内容?

我想要“nodeContent”内的值

谢谢。

回答

1

从查看数据结构来看,在我看来,根结构是一个List,而不是您在问题中提出的字典。那是对的吗?如果是这样的话,然后打印属性值到控制台将是一个迭代:

NSArray *array; // this is your list with 50 values or so in it 
//... some code to load the data into array 
NSDictionary *d; 
for (NSDictionary *period in array){ 
    NSLog(@"%@",[period objectForKey:@"nodeName"]); 
    for (NSDictionary *nodeAttributeArray in [period objectForKey:@"nodeAttributeArray"]){ 
     NSLog(@"\t%@=%@",[nodeAttributeArray objectForKey:@"attributeName"],[nodeAttributeArray objectForKey:@"nodeContent"]); 
    } 
} 
+0

其实我不是很sure..But此得到由XML解析器,这表示返回的返回类型为NSDictionary ...(http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html) 我只是在控制台调试它,它说; replist_rptdt_dict的 印刷描述: ( { nodeAttributeArray =( { 的attributeName = ReportDate; ...... – testndtv 2011-01-23 11:23:46