[
{
  "result": 1,
  "max_qty": "10",
  "msg": [
    {
      "product_id": "39",
      "product_name": "Cabbage",
      "product_price": "18",
      "product_image": "product/39.jpg",
      "product_description": "Fresh Cabbage",
      "product_category": "1",
      "product_qty": [
        {
          "quantity_id": "3",
          "quantity_name": "500 gm",
          "value": "500",
          "quantity_status": "1"
        },
        {
          "quantity_id": "4",
          "quantity_name": "1 Kg",
          "value": "1000",
          "quantity_status": "1"
        }

In this "msg" which is an array and contains value in form of object but "product_qty" again an array which is under the object,now how can i fetch the elements value of product_qty ]1

3

There are 3 best solutions below

0
iCoderz Developers On BEST ANSWER
Updated Code:

NSDictionary *mainDic = [arrResponse objectAtIndex:0];

NSArray *arrMsg = [mainDic valueForKey:@"msg"];

for (NSDictionary *dicSub in arrMsg) {

NSArray *arrProdQuality = [dicSub valueForKey:@"product_qty"];

for (NSDictionary *dicQuality in arrProdQuality) {

NSLog(@"quantity_name %@",[dicQuality valueForKey:@"quantity_name"]);

}
}
0
CodeChanger On

You need to fetch key value like this:

NSDictionary *dictProducts =  array[0]; // From Main Array.
NSArray *allProduct = dictProducts[@"msg"]; // Form Dictionary.
NSDictionary *firstProduct = allProduct[0];
NSLog(@"Product Qty : %@", firstProduct[@"product_qty"]); // Here you can get product_qty array.

Hope this will helps.

0
saurabh rathod On

just used this if([array containsObject dict]) { already in your array } else { not in your array }