1

So I have the following JSON structure

{"id":"941","title":"dsadadadadsad","description":"dsadadadsadad","added":"2017-01-10 19:00:47"}

Now I'm trying to make a request and output the data, but I can't access the json property: object.description

I'm trying this and doesn't work

    Alamofire.request("http://localhost:8080/foo.php").responseJSON{ response in
        if let JSON = response.result.value {
            print(JSON["description"])
        }
    }

It doesn't build. How can I output the value of "description"?

//LE error enter image description here

Uffo
  • 9,628
  • 24
  • 90
  • 154

1 Answers1

1

You should unwrap value like this :

if let JSON = response.result.value as? [String: Any] {
            //deal with JSON["description"
}

You can also unwrap this like [String:String] if your JSON contains only String values

kamwysoc
  • 6,709
  • 2
  • 34
  • 48