kinza kinza - 5 months ago 48
JSON Question

Dealing with DataResponse<Any> in Xcode 8 (Swift)

I am a newbie to iOS and I am using alamofire. When i call the API the result is successfully getting printed to console as shown


What I want is, to only extract the message from this response and present it to user. How to do it?
I have searched for this but I found content related to converting string to JSON object or JSON object to JSON string. But my response is of type

and I don't know exactly how to deal with it.

P.s I am using Xcode 8, Swift 3.

Answer Source

You can try something like this:

if let object = response.result.value as? [String:Any], let message = object["message"] as? String {
    print(message) // "User has been successfully registrered"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download