Search code examples
jsonswiftalamofire

how to convert JSON dictionary to string value in swift 4


I'm new to Swift and I started working on a Swift 4 project with a PHP server. I use Alamofire for requests, and print the data using print(). This is is what i'm getting:

{"error":false,"n":"Raghad"}

But when I want to convert it to String, it returns "" (empty) and when I convert to boolean it returns the value correctly.

So, how can I fix it?

let wJSON : JSON = JSON(response.result.value!)
print(wJSON["n"].stringValue)
print(wJSON["error"].boolValue)

Solution

  • I change the responseString to responseJSON

    Alamofire.request(Url!, method: .post, parameters: par).validate().responseJSON { response in if response.result.isSuccess { let wJSON : JSON = JSON(response.result.value!)

    and it's work