We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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:
struct doh: Codable { var homer = "" } extension doh : ArrowParsable { public mutating func deserialize(_ json: JSON) { homer <-- json["homer"] } }
now to create one:
let myJson = "{ \"homer\": \"simpson\"}" var aSimpson = doh() aSimpson.deserialize(JSON(myJson)!)
this doesn't work! How do I create a doh object from the myJson string?
doh
myJson
Thanks.
The text was updated successfully, but these errors were encountered:
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)
JSONSerialization
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.deserialize(json)
aSimpson <-- json
Hope this helps :)
Sorry, something went wrong.
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 :)
No branches or pull requests
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.
The text was updated successfully, but these errors were encountered: