[Solved] How to parse JSON using Alamofire 4.7 in Swift 4


As per the docs, this is how you access the serialised JSON response:

if let json = response.result.value as? [String: Any] {
    print("JSON: \(json)") // serialized json response
}

To access api_key you just need to unwrap the success and user dictionaries first and then you can access the api_key property in the user dictionary.

guard let user = json["user"] as? [String: Any],
      let apiKey = user["api_key"] as? String else {

      print("Failed to parse JSON")
      return
}

print(apiKey)

8

solved How to parse JSON using Alamofire 4.7 in Swift 4