Good day! I have a local JSON file in the project and I need to get data from it. but for some reason, when I try to output this data to the console, I write "(null)" in the console, instead of displaying the data. Please help me out!
Json
{"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"} ]} Objective-c
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"citiesJSON" ofType:@"json"]; NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; NSData *data = [NSData dataWithContentsOfFile:filePath]; NSError *error = nil; NSDictionary *parsedJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSArray *cityNames = [parsedJSON objectForKey:@"cityName"]; NSLog(@"%@", cityNames); http://www.cyberforum.ru/objective-c/thread1570741.html#post8288750