-3
{
    Address =     (
                {
            address = "Bengaluru, Karnataka 560008, India";
            "address_id" = 29;
            "address_title" = "";
            "building_name" = "";
            latitude = "23.95579108";
            longitude = "77.64169808";
            "user_id" = 13;
        },
                {
            address = "Bengaluru, Karnataka 560008, India";
            "address_id" = 31;
            "address_title" = "";
            "building_name" = "";
            latitude = "22.95578162";
            longitude = "77.64173089";
            "user_id" = 13;
        },
                {
            address = "Bengaluru, Karnataka 560008, India";
            "address_id" = 37;
            "address_title" = "";
            "building_name" = "";
            latitude = "22.95577373";
            longitude = "77.64173507";
            "user_id" = 13;
        },
                  {
            address = "256, Road Number 19, Wadla Village, Vadala, Mumbai, Maharashtra 400031, India";
            "address_id" = 49;
            "address_title" = dsa;
            "building_name" = das;
            latitude = "19.01761470";
            longitude = "72.85616440";
            "user_id" = 13;
        }
    );
}

I'm trying to retrive data from the JSON dictionary. I need to fetch the datas in address from the Address dictionary and store it in an array . My Array should look like this : [Bengaluru, Karnataka 560008, India,Bengaluru, Karnataka 560008, India,Bengaluru, Karnataka 560008, India,256, Road Number 19, Wadla Village, Vadala, Mumbai, Maharashtra 400031, India]

Need help please .

2 Answers2

0

Filtering NSDictionary with predicate

You can filter an NSDictionary with an NSPredicate.

Assuming your dictionary is NSDictionary *dict

NSArray *resultArray = [[dict objectForKey:@"Address" allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(key == %@)", @"address"]];
Community
  • 1
  • 1
dmorrow
  • 5,152
  • 5
  • 20
  • 31
0
NSMutableArray *resultArray = [NSMutableArray new];   
NSError *jsonError = [[NSError alloc] init];
NSDictionary *pR = [NSJSONSerialization JSONObjectWithData:yourJsonObject options:NSJSONReadingAllowFragments error:&jsonError];
NSArray *pArray = pR[@"Address"];

for(NSDictionary *dict in pR)
{
    [resultArray addObject:dict[@"address"]];
}
Jad Feitrouni
  • 637
  • 6
  • 12