对象中的 NSMutableDictionary 和 NSMutableArray 对象

NSMutableDictionary and NSMutableArray object in object

我正在用 NSDictionaryNSArray 为键东西添加对象来砸我的头。

我有 2 个可变数组,我想将它们组合起来。

NSMutableArray 1 :

 {
        email = "a@a1.com";
        "password" = "2017-05-23 13:08:03";
    }

NSMutableArray 2

(
        {
        "created_at" = "2017-06-22 00:00:00";
        "id_weather_city" = 1;
        name = Cityname;
        "updated_at" = "2017-06-22 00:00:00";
    },
        {
        "created_at" = "2017-06-22 00:00:00";
        "id_weather_city" = 2;
        name = Cityname2;
        "updated_at" = "2017-06-22 00:00:00";
    }
)

我想像这样把它们组合在一起,但我不知道如何 右数组:

{
    email = "a@a1.com";
    "password" = "2017-05-23 13:08:03";
    "weather":(
        {
        "created_at" = "2017-06-22 00:00:00";
        "id_weather_city" = 1;
        name = Cityname;
        "updated_at" = "2017-06-22 00:00:00";
    },
        {
        "created_at" = "2017-06-22 00:00:00";
        "id_weather_city" = 2;
        name = Cityname2;
        "updated_at" = "2017-06-22 00:00:00";
    }
)
}

试试这个:

NSMutableDictionary *finalDictionary =  [[array1 objectAtIndex : 0] mutableCopy];
[finalDictionary setValue : array2 forKey:@"weather"];

第一个不是数组,是字典。知道你可以做到

NSMutableDictionary *dict = [item1 mutableCopy];
dict[@"weather"] = [item2 copy];

只需复制第一个字典,并为 weather 键插入第二个字典