[Solved] parse json using objective-c [closed]


you need to get the key as per your json.
using that keys you will get the data.

 NSURL * url=[NSURL URLWithString:@"http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"];   // pass your URL  Here.

        NSData * data=[NSData dataWithContentsOfURL:url];

        NSError * error;

        NSMutableDictionary  * json = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];

        NSLog(@"%@",json);


        NSMutableArray * referanceArray=[[NSMutableArray alloc]init];

        NSMutableArray * periodArray=[[NSMutableArray alloc]init];

        NSArray * responseArr = json[@"days"];

        for(NSDictionary * dict in responseArr)
        {

            [referanceArray addObject:[dict valueForKey:@"reference"]];
            [periodArray addObject:[dict valueForKey:@"period"]];

        }


        NSLog(@"%@",referanceArray);   // Here you get the Referance data
        NSLog(@"%@",periodArray);      // Here you get the Period data

Here you used

[referanceArray addObject:[dict valueForKey:@"reference"]];

used all this keys to get data.

Try this code.

1

solved parse json using objective-c [closed]