I have working json data parsing array codes but I want to change it to Dictionary parsing. My new json file
{
"Id": 450,
"Name": "NameforItem",
"Image": "234234.jpg"
}
My old json file working success
[{
"Id": 450,
"Name": "NameforItem",
"Image": "234234.jpg"
}]
My parsing codes.
/// Convert JSON data into array
private func getFromJSON(jsonData: NSData) throws -> [Place] {
var places = [Place]()
do {
if let jsonArray = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments) as? [[String: AnyObject]] {
for i in jsonArray {
var properties = [String: AnyObject]()
properties[placeJSONKeys.Id] = i[placeJSONKeys.Id]
properties[placeJSONKeys.Name] = i[placeJSONKeys.Name]
let place = Place(properties: properties)
places.append(place)
}
}
} catch {
throw TMDBErrors.ParsingError
}
return places
}
Thank you !