如何从 NSDictionary 键加载 NSMutableArray

How to load NSMutableArray from NSDictionary key

我想将@"Color"、@"size"、@"Product_Img"键的值添加到不同键的不同NSMutable数组中

我的 NSDictionary 结构是....

{
Color =     (
            {
        "color_name" = Red;
        id = 1;
    },
            {
        "color_name" = Black;
        id = 2;
    },
            {
        "color_name" = white;
        id = 3;
    },
            {
        "color_name" = Pink;
        id = 4;
    },
            {
        "color_name" = Green;
        id = 5;
    }
);
"Product_Img" =     (
            {
        "product_image" = "15131445991.jpg";
        "product_image_id" = 94;
    }
);
"product_type" = product;
size =     (
            {
        size = "6 Kg";
    },
            {
        size = "7 Kg";
    },
            {
        size = "8 Kg";
    },
            {
        size = "9 Kg";
    }
);

}

我的代码是我尝试实现的...

viewDidLoad

self.arrProductSizeList = [NSMutableArray array];
self.arrProductColorList = [NSMutableArray array];
self.arrProductImageList = [NSMutableArray array];

在 configureData 方法中...

[self.arrProductImageList removeAllObjects];
[self.arrProductImageList addObjectsFromArray:[_dictProductDetails objectForKey:@"Product_Img"]];

[self.arrProductColorList removeAllObjects];
[self.arrProductColorList addObjectsFromArray:[_dictProductDetails objectForKey:@"Color"]];

[self.arrProductSizeList removeAllObjects];
[self.arrProductSizeList addObjectsFromArray:[_dictProductDetails objectForKey:@"size"]];

NSLog...

NSLog(@"Size Array List%@", _arrProductSizeList);
NSLog(@"Color Array List%@", _arrProductColorList);
NSLog(@"Image Array List%@", _arrProductImageList);

提前致谢

也许你可以试试这些代码:

self.arrProductSizeList = [_dictProductDetails[@"Product_Img"] mutableCopy];

self.arrProductColorList = [_dictProductDetails[@"Color"] mutableCopy];

self.arrProductImageList = [_dictProductDetails[@"size"] mutableCopy];