I am trying to parse JSON data in a form of
Dictionary
if let valueTripleDictionary = jsonDataDictiony["value"] as? [String : AnyObject]
{
if let valueDoubleDictionary = valueTripleDictionary as? [String : AnyObject]
{
if let valueDictionary = valueDoubleDictionary as? [String : AnyObject]
{
self.busStopCode = valueDictionary["BusStopCode"] as? String
self.roadName = valueDictionary["RoadName"] as? String
self.busStopDescription = valueDictionary["Description"] as? String
self.busStopLatitude = valueDictionary["Latitude"] as? Double
self.busStopLongitude = valueDictionary["Longitude"] as? Double
print(busStopCode)
print(roadName)
print(busStopDescription)
print(busStopLatitude)
print(busStopLongitude)
}
}
}
["value": <__NSArrayI 0x7fe884d24f00>(
{
BusStopCode = 01012;
Description = "Hotel Grand Pacific";
Latitude = "1.29684825487647";
Longitude = "103.8525359165401";
RoadName = "Victoria St";
},
{
BusStopCode = 01013;
Description = "St. Joseph's Ch";
Latitude = "1.29770970610083";
Longitude = "103.8532247463225";
RoadName = "Victoria St";
}
)
]
value
key contains Array
not Dictionary
, so you need to write [[String : AnyObject]]
instead of [String : AnyObject]
.
if let array = jsonDataDictiony["value"] as? [[String : AnyObject]] {
for dic in array {
print(dic["BusStopCode"]) //Access other values same way
}
}