I am trying to get an array with a kist of countries from a JSON file. I found 2 JSON files online of the formats below. I can load into an NSDictionary, my question is how to extract and format. These don't have a key to extract by. I am guessing I need a for loop but not sure how to do.
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Ã…land Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
and
[
{
"name": "Afghanistan",
"nativeName": "\u0627\u0641\u063a\u0627\u0646\u0633\u062a\u0627\u0646",
"tld": [".af"],
"cca2": "AF",
"ccn3": "004",
"cca3": "AFG",
"currency": ["AFN"],
"callingCode": ["93"],
"capital": "Kabul",
"altSpellings": ["AF", "Af\u0121\u0101nist\u0101n"],
"relevance": "0",
"region": "Asia",
"subregion": "Southern Asia",
"language": ["Pashto", "Dari"],
"languageCodes": ["ps", "uz", "tk"],
"translations": {
"cy": "Affganistan",
"de": "Afghanistan",
"es": "Afganist\u00e1n",
"fr": "Afghanistan",
"it": "Afghanistan",
"ja": "\u30a2\u30d5\u30ac\u30cb\u30b9\u30bf\u30f3",
"nl": "Afghanistan",
"hr": "Afganistan"
},
"latlng": [33, 65],
"demonym": "Afghan",
"borders": ["IRN", "PAK", "TKM", "UZB", "TJK", "CHN"],
"area": 652230
},
{
"name": "\u00c5land Islands",
"nativeName": "\u00c5land",
"tld": [".ax"],
"cca2": "AX",
"ccn3": "248",
My code to extract dictionary (from first json file)
+ (NSDictionary *)getCountryList
{
NSURL *myURL = [[NSURL alloc]initWithString:@"http://www.osmi-tech.com/iphone/json/countriessimp.json"];
NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL];
NSError *error = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:&error];
return json;
}