There is a local file inside the project, and I need to parse specific data from it - cityName , and I only have to parse the entire file (the value of the cities array). How to get the value cityName from it?
Here is the JSON file code
{"cities":[ {"cityName":"Minsk", "countryCode":"BY", "cityDescription":"Minsk is the capital of Belarus"}, {"cityName":"Moscow", "countryCode":"RUS", "cityDescription":"Moscow is the capital of Russia"}, {"cityName":"Prague", "countryCode":"CZ", "cityDescription":"Prague is the capital of Czech Republic"}, {"cityName":"Washington", "countryCode":"USA", "cityDescription":"Washington is the capital of United States of America"}, {"cityName":"Stockholm", "countryCode":"SWN", "cityDescription":"Stockholm is the capital of Sweden"}, {"cityName":"Beijing", "countryCode":"СHN", "cityDescription":"Beijing is the capital of China"}, {"cityName":"Tokyo", "countryCode":"JPN", "cityDescription":"Tokyo is the capital of Japan"}, {"cityName":"London", "countryCode":"UK", "cityDescription":"London is the capital of Great Britain"}, {"cityName":"Madrid", "countryCode":"SPN", "cityDescription":"Madrid is the capital of Spain"}, {"cityName":"Paris", "countryCode":"FR", "cityDescription":"Paris is the capital of France"} ]} Here is the code on Objective-C
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"citiesJSON" ofType:@"json"]; NSData *data = [NSData dataWithContentsOfFile:filePath]; NSError *error = nil; NSDictionary *parsedJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSArray *cities = [parsedJSON objectForKey:@"cities"]; NSLog(@"%@", cities);