KAR KAR - 1 month ago 4x
iOS Question

How to get dictionary and array from 'http://country.io/names.json'

I am new to json.

I want to know that how can I get code and name of country from


and display it in label.

I only want to know objectForKEy and valueForKey for this.

I want output like,

Before Country Name, I want Country Code from API

I want Output like,

IN India

In my tableView

I have two label in my cell, one for Code and another for name.


do like

NSMutableArray *Name = [[NSMutableArray alloc] init];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://country.io/names.json"]];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

for (NSString *findkey in [json allKeys]) {
    //[Name addObject:[json objectForKey:findkey]];
      [Name addObject:[NSString stringWithFormat:@"%@  %@",findkey,[json objectForKey:findkey]]];


you get output like

enter image description here