Closed ntkon closed 6 years ago
Hi @ntkon,
You need to go through native JSONSerialization
in order for it to work.
(Actually this could be a great future improvement to support JSON strings)
Here is the working version:
let myJson = "{ \"homer\": \"simpson\"}"
guard let jsonData = myJson.data(using: .utf8),
let jsonObject = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers),// as? NSDictionary,
let json = JSON(jsonObject) else {
return
}
var aSimpson = doh()
aSimpson.deserialize(json)
print(aSimpson)
Also the aSimpson.deserialize(json)
part can be written like:
aSimpson <-- json
Hope this helps :)
Thanks @s4cha, much appreciated. I'm liking using arrow, ws and stevia - nice tools.
@ntkon can we close this ?
Sorry, I forgot to do that. Closed :)
Hi, sorry to ask such a dumb question, but I can't figure out how to do a simple decode from a string containing my json to my model object:
now to create one:
this doesn't work! How do I create a
doh
object from themyJson
string?Thanks.