循环遍历 NSDictionary 创建 NSArray
我有以下 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);
}
我得到“key”中的每个数据“数组”......但是如何将它从那里分解成它自己的数组?抱歉,如果我感到困惑。 =)
感谢您的帮助!
I have the following NSDictionary data:
{
"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";
},
And I am trying to figure out how convert this data into arrays. With this example I need to have it broken down into 2 arrays with those arrays filled with it's data (hope that made sense).
I can loop through the data like this:
NSString *key;
for (key in finalDict) {
NSLog(@"%@", key);
}
And I get each "array" of data in "key" ... but how to I break it down from there into it's own arrays? Sorry if I'm confusing. =)
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,从你的代码来看,在我看来你有一个 NSDictionaries 的 NSArray 。如果您实际上想将所有数据加载到 UITableView 中,我建议您在 cellForRowAtIndexPath 方法中创建一个 NSDictionary 并使用当前索引 NSDictionary 加载它,如下所示:
当然,这取决于您如何设置 UITableViewCell 以及是否或者你是否想要每个属性都有出口。
希望这有帮助。
So, it looks to me like you have an NSArray of NSDictionaries, judging by your code. If you actually want to load all the data into a UITableView I would suggest that in your cellForRowAtIndexPath method, you create an NSDictionary and load it with the current indexes NSDictionary like this:
Of course, it depends on how you set up your UITableViewCell and whether or not you want to have outlets for each attribute or not.
Hope this helps.
将
key
设为NSArray
类型,而不是NSString
。然后您可以访问数组的元素,将它们添加到另一个数组或您想要执行的任何其他操作。 这里是<代码> NSArray 文档。Make
key
anNSArray
type instead ofNSString
. Then you can access the array's elements, adding them to another array or whatever else you want to do. Here is theNSArray
documentation.