Reputation: 5303
I'm trying to use this FunctionalJSON-swift to parse JSON to object but I can't figure out how to use method performRequest
from NetworkClient
and obtain my User
object. This is what I have:
let url = NSURL(string: "http://localhost/my_app/user.json")
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
performRequest(request, callback: { (data: Result<User>) -> () in
// how obtain User?
})
This is output from url, I think it's all right at this point:
{"id":1,"name":"User Name","email":"[email protected]"}
Upvotes: 1
Views: 160
Reputation: 1860
First of all, I apologize if this is not the type of answer you seek, as I am going to do this using another library but in a really quick manner thanks to it.
It is actually a library that I wrote based on the ideas on that repo's blog post. You can get it here: JSONHelper
As to the answer: Just get the response as a string and, let's assume that it is stored in a string variable named responseString, deserialize it like this:
var user: User?
user <<<< responseString
Upvotes: 1