【发布时间】:2016-07-18 23:11:47
【问题描述】:
我一直在开发一个应用程序,我必须使用 alamofire 来发布。 但是,我不断收到错误,说
失败 错误:反馈提交失败。 Optional("操作无法完成。JSON无法序列化。输入数据为nil或零长度。")
我的代码是这样的
let reportJSON: [String : AnyObject] = [
"Name" : nameTextField.text!,
"Message" : reportTextView.text!
]
Alamofire.request(.POST, "API", parameters: reportJSON, encoding: .JSON).responseJSON{ response in
print(response.result)
guard response.result.error == nil else{
print("Error: feedback submission failed.")
print(response.result.error?.localizedDescription)
return
}
if let responseValue = response.result.value{
let recipeList = JSON(responseValue)
print(recipeList)
}
}
我对 .GET 没有任何问题,但我不知道如何使用 .POST。 任何帮助表示赞赏。
【问题讨论】:
-
我解决了这个问题。也许对其他人来说很明显,但我收到的数据不是 JSON 格式的。所以我不得不使用 responseData,而不是 responseJSON。