如何在Objective C中从数组中的数组打印字典数据

时间:2016-07-26 10:38:42

标签: objective-c json nsmutablearray xcode7.3

如何打印ActivityName&说明

我有这种情况作为回应我需要解析这些数据并打印ActivityId,ActivityName&描述

 Project List Array Activites List:= Array
 (
   (
     { 
        ActivityID = 4;
        ActivityName = Development;
        Description = Development;
        IsActive = 1;
      },
     ),
  )

2 个答案:

答案 0 :(得分:0)

你可以为每个循环使用两个

projectListArray成为您的第一个数组,projectList为其中的每个数组,projectDict为其中的每个字典。

for (NSArray *projectList in projectListArray) {
    for (NSDictionary *projectDict in projectList) {
       NSLog(@"Activity ID = %d",[projectDict objectForKey:@"ActivityID"]);
       NSLog(@"Activity Name = %d",[projectDict objectForKey:@"ActivityName"]);
       NSLog(@"Description = %d",[projectDict objectForKey:@"Description"]);
    }
}

答案 1 :(得分:0)

首先获取Plist到数组

NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"yourPlistName" ofType:@"plist"];
NSMutableArray *arrPlist = [NSMutableArray arrayWithContentsOfFile:stringPath];

然后从数组中获取数据

for(int i=0;i<arrPlist.count;i++)
{
  NSString *strID = [NSString stringWithFormmat:@"%@",[arrPlist objectAtIndex:i]objectForKey:@"ActivityID"]];
  NSString *strName = [NSString stringWithFormmat:@"%@",[arrPlist objectAtIndex:i]objectForKey:@"ActivityName"]];
  NSString *strDesc = [NSString stringWithFormmat:@"%@",[arrPlist objectAtIndex:i]objectForKey:@"Description"]];
}