我正在尝试使用Alamofire阅读JSON。这是我的代码:
let headers = ["Content-Type": "application/json"]
func getConfirmationCode(params: [String:Any], block: @escaping(_ data : JSON, _ success : Bool) -> Void) {
if let url = URL(string: baseURL + "getConfirmationCode.php") {
Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in
DispatchQueue.main.async {
if let value = response.result.value {
let json = JSON(value)
block(json, true)
} else {
block(JSON.null, false)
}
}
}
}
}
JSON是有效的,一切都在Postman中完美运行,但我无法使它工作。 Web上的任何建议都没有帮助(将responseJSON更改为responseString / responseData,将JSONEncoding.default更改为URLEncoding.default等)
谁能帮我?