1

This is JSON data

{"response":[{"uid":1,"first_name":"Павел","last_name":"Дуров","hidden":1}]}

How to get "first_name" value using SwiftyJSON

i tried so

Alamofire.request(.GET, "https://api.vk.com/method/users.get?", parameters: ["user_id": ID])
            .responseJSON { response in


                if let jsonData = response.result.value {
                    let first_name = JSON(jsonData)["first_name"].string
                    print("First name = \(first_name)")

                }
        }

but in output i have this: First name = nil

please help!

Dmitry
  • 2,963
  • 2
  • 21
  • 39

1 Answers1

4

The value for your "response" key is an array.

let result = JSON(jsonData)["response"].arrayValue
let first_name = result[0]["first_name"].string

Remember, JSON arrays begin with [ and JSON dictionaries begin with {.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253