0
我不能確定如何解析嵌套JSON輸出。我正在使用Google Googles JSON地理編碼並嘗試提取座標。我在想我需要另一個級別的解析。我的代碼不工作:IPhone谷歌JSON解析Geocoing
hostStr = [hostStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *hostURL = [NSURL URLWithString:hostStr];
NSString *jsonString = [[NSString alloc] initWithContentsOfURL:hostURL];
self.jsonArray = [jsonString JSONValue];
NSDictionary *coordinates = [self.jsonArray objectForKey:@"id:p1"];
NSLog(coordinates);
NSString *point = [coordinates objectForKey:@"Point"];
NSLog(point);
的JSON:
{
"name": "11111 WASHINGTON AVE # 116 SAN PEDRO, CA 91111",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "11111 Washington Ave, San Pedro, CA 91111, USA",
"AddressDetails": {
"Accuracy" : 8,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "CA",
"Locality" : {
"LocalityName" : "San Pedro",
"PostalCode" : {
"PostalCodeNumber" : "91111"
},
"Thoroughfare" : {
"ThoroughfareName" : "Washington Ave"
}
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 37.7026153,
"south": 37.6999173,
"east": -122.1393925,
"west": -122.1420904
}
},
"Point": {
"coordinates": [ -122.1407313, 50.7012704, 0 ]
}
} ]
}
非常好。謝謝。 – savagenoob 2011-12-29 21:33:24
如果我有其餘的json看起來像:( -122.1407313, 37.7012704,)如何將第一個和第二個座標不帶對象ID拉入變量? – savagenoob 2011-12-29 21:47:14
你'NSArray'命名爲「座標」包含這些,我的代碼示例有結束。因此,使用'objectAtIndex:0'來獲取緯度和'objectAtIndex:1'來獲得經度。這些都是浮動的,所以它看起來像'NSNumber * latitude = [coordinate objectAtIndex:0];' – 2011-12-30 13:41:01