Sauron
Sauron

Reputation: 6657

Parsing JSON Swift 3

I am running iOS 9.0, Swift 3 on Xcode8 and implementing Facebook into my app, the result object returns successfully as:

Optional({
    email = "[email protected]";
    "first_name" = name;
    id = 1015396591;
    "last_name" = lastName;
    picture =     {
        data =         {
            "is_silhouette" = 0;
            url = "https://scontent.xx.fbcdn.net/v/t1.0-1/s200x200/1915003_414206574090_5019436_n.jpg?oh=bf120460b36b26c648185d6777a&oe=5892EB78";
        };
    };
})

However, attempting to access the elements as: result["email"] as! String, notes the error Type Any? has no Subscript Members

How can I allow the element to be read?

Upvotes: 0

Views: 110

Answers (1)

LC 웃
LC 웃

Reputation: 18998

Use this to get email

let result = result as! Dictionary<String,Any>
let email = result["email"] as! String

Upvotes: 1

Related Questions