我有以下NSDictionary数据:
{
"ADDED_DATE" = "2011-02-04 00:56:44.732014";
"ADDED_LOGON" = ABCD;
"AGENT_BROKER_IND" = N;
"ALLOCATION_IND" = AUTOPROP;
"BILLPRINT_DLVY_IND" = PAPER;
"BILLPRINT_LOCATION_NAME" = "COMPANY ABC";
"BILLPRINT_LVL_CIM" = 05852015;
"BILL_DUE_DT" = "2011-02-01";
"BILL_LOGO_CD" = XXLOGO;
"BILL_PERIOD_MONTH" = 02;
"BILL_PER_BEG_DT" = "2011-02-01";
"BILL_PER_END_DT" = "2011-02-28";
"BILL_RUN_DT" = "2011-02-03";
"BILL_TOTAL_PREMIUM" = "342.84";
IDX = ".000339709222474931";
"LIST_BILL_CASE_NUM" = 0318T4;
"LIST_BILL_CIM" = 05852019;
"OWNING_CARRIER" = WX;
"PAST_DUE_DT" = "2011-03-04";
"REMIT_CYCLE" = MONTHLY;
"RUN_NUMBER" = 1;
"TOTAL_ADJUSTMENTS" = "0.00";
"TOTAL_AMOUNT_DUE" = "685.68";
"TOTAL_CURRENT_CHARGES" = "342.84";
"TOTAL_PASTDUE_AMOUNT" = "342.84";
},
{
"ADDED_DATE" = "2010-12-04 08:20:45.292516";
"AGENT_BROKER_IND" = N;
"ALLOCATION_IND" = AUTOPROP;
"BILLPRINT_DLVY_IND" = WEBPORTAL;
"BILLPRINT_LOCATION_NAME" = "ANCHOR ABC";
"BILLPRINT_LVL_CIM" = 05721991;
"BILL_DUE_DT" = "2010-12-15";
"BILL_FORM_TYPE_CD" = FE4;
"BILL_LOGO_CD" = XXLOGO;
"BILL_PERIOD_MONTH" = 01;
"BILL_PER_BEG_DT" = "2011-01-01";
"BILL_PER_END_DT" = "2011-01-31";
"BILL_RUN_DT" = "2010-12-03";
"BILL_TOTAL_PREMIUM" = "277.96";
IDX = ".000389371998789428";
"LIST_BILL_CASE_NUM" = 9858Q8;
"LIST_BILL_CIM" = 05721991;
"OWNING_CARRIER" = FE;
"PAST_DUE_DT" = "2010-12-31";
"REMIT_CYCLE" = MONTHLY;
"RUN_NUMBER" = 1;
"TOTAL_ADJUSTMENTS" = "0.00";
"TOTAL_AMOUNT_DUE" = "277.96";
"TOTAL_CURRENT_CHARGES" = "277.96";
"TOTAL_PASTDUE_AMOUNT" = "0.00";
},
我正在试图弄清楚如何将这些数据转换为数组。在这个例子中,我需要将它分解为2个数组,这些数组填充了它的数据(希望有意义)。
我可以像这样遍历数据:
NSString *key;
for (key in finalDict) {
NSLog(@"%@", key);
}
我在“密钥”中获取每个“数组”数据......但是如何将其从那里分解为它自己的数组?对不起,如果我很困惑。 =)
感谢您的帮助!
答案 0 :(得分:1)
将key
设为NSArray
类型,而不是NSString
。然后,您可以访问数组的元素,将它们添加到另一个数组或其他任何您想要做的事情。 Here是NSArray
文档。
答案 1 :(得分:1)
所以,在我看来,你有一个NSArray的NSDrary,从你的代码判断。如果您确实想要将所有数据加载到UITableView中,我建议您在cellForRowAtIndexPath方法中创建一个NSDictionary并使用当前索引NSDictionary加载它,如下所示:
NSDictionary *currentDictionary = [self.myArrayOfDictionaries objectAtIndex:indexPath.row];
//now do some stuff with your dictionary
cell.addedDate.text = [currentDictionary objectForKey:@"ADDED_DATE"];
cell.agentBrokerInd.text = [currentDictionary objectForKey:@"AGENT_BROKER_IND"];
///etc.....
当然,这取决于您如何设置UITableViewCell以及是否要为每个属性设置出口。
希望这有帮助。