Open giacmarangoni opened 7 years ago
I'm not really sure where Marshal thinks you're getting an array from given your example. But that's what it seems to think.
As to the first part of the question, that's tricky. Marshal isn't designed around this use case. My best suggestion would be to not use any of Marshal's built in helpers for converting collections, and instead do your own for map over the key value pairs of your dictionary. Then, inside the loop, init a a new student object using the dictionary's value, and then set the id to the key.
in other words, something maybe like
let students = json.map { key, value in
var student = try Student(object: value)
student.id = key
return student
}
Thank you for your help. It works.
Hi guys, I really want to thank you for you awesome work, I think Marshal is the fastest and lightweight library to deal with JSON structures. I'm facing a problem parsing a simple data structures:
Here my model class:
I don't exactly how to assign key to model id and additionally I'm getting and error while extracting courses dictionary: fatal error:
try!' expression unexpectedly raised an error: Type mismatch. Expected type Dictionary<String, Int> for key: courses. Got '__NSArray0
Do you have any suggestion? Thank you so much