检索多行xml数据到字典

时间:2012-04-17 20:34:24

标签: objective-c ios5

我正在尝试从xml数据中返回多行。我已将结果加载到字典中。下面的代码给出了最后的结果(第1行或Randy)。如何检索所有结果而不是最后一个结果?我正在寻找CSHR_POS_NAME,其中[ID.text intValue] == CSHR_NUM。

dict = [resp objectForKey:@"TC"];
 if( ( dict == nil ) || ![dict isKindOfClass:[NSDictionary class]] ) {
  NSLog( @"WARNING: %@", [dict description]);
  return;
}

desc = [[dict objectForKey:@"CSHR_POS_NAME"]copy];
CashierNum = [[dict objectForKey:@"CSHR_NUM"]copy];

NSLog(@"Name: %@ and Cashier Number: %@",desc, CashierNum);

xml输出的日志是:

<NewDataSet xmlns="">
  <TC diffgr:id="TC1" msdata:rowOrder="0">  
    <CSHR_POS_NAME>BRITTANY</CSHR_POS_NAME>
    <CSHR_NUM>66</CSHR_NUM>
  </TC>
  <TC diffgr:id="TC4" msdata:rowOrder="1">
    <CSHR_POS_NAME>Randy</CSHR_POS_NAME>
    <CSHR_NUM>7</CSHR_NUM>
  </TC>
</NewDataSet> 
</diffgr:diffgram>

1 个答案:

答案 0 :(得分:1)

看来你有一个带有"TC"键的字典数组。您是否应该尝试将响应作为数组读取,然后遍历字典?