Thripthi Haridas
Thripthi Haridas

Reputation: 363

Convert socket response to dictionary in Swift

I'm getting response from socket as below:

(
    {
    response =   {
        demo =   (           
                            {
                "code" = 612064;
                "code1" = "T";
                "code2" = "http://www.XXXXXXX.com";
            }        
        );
        response = "get_nearby";

    };
    status = success;
    }
)

How to convert to dictionary?

Upvotes: 0

Views: 300

Answers (1)

Nirav D
Nirav D

Reputation: 72460

The response you are showing is not Dictionary it is Array of Dictionary, So try to convert your response to [[String:AnyObject]].

if let array = yourResponse as? [[String:AnyObject]], let firstDic = array.first {
    print(firstDic)
    print(firstDic["status"])
}  

Upvotes: 2

Related Questions