ios 如何从数组中获取日期值?

nxowjjhe  于 2023-01-10  发布在  iOS
关注(0)|答案(2)|浏览(136)

我想把date存储在一个单独的数组中.....怎么做???我有点糊涂了....请帮帮我....

(
    {
    "2015-03-27" =         {
        amount = 13086;
        date = "2015-03-26 18:30:00 +0000";
        "date-day" = 27;
        "date-month" = Mar;
        "date-year" = 2015;
        units = 2160;
    };
},
    {
    "2015-08-03" =         {
        amount = 18300;
        date = "2015-08-02 18:30:00 +0000";
        "date-day" = 03;
        "date-month" = Aug;
        "date-year" = 2015;
        units = 2950;
    };
},
)
yacmzcpb

yacmzcpb1#

您的数据在数组中(字典的集合)
因此,首先从数组中获取字典,然后将特定字典的键添加到新数组中(这是日期的结果数组)
试试这个:

NSArray *arrData;

NSMutableArray *arrDates = [NSMutableArray array];

for (NSDictionary *dict in arrData) {
    
    [arrDates addObject:[[dict allKeys] firstObject]];
}

NSLog(@"Dates :: %@", arrDates);
afdcj2ne

afdcj2ne2#

外部对象是一个数组,项0包含两个字典。

NSDictionary *dictionary = array[0];

然后枚举字典并提取date

NSMutableArray *dates = [NSMutableArray array];
for (NSString *key in dictionary) {
   [dates addObject: dictionary[key][@"date"]];
}

相关问题