json - swift :阿拉莫菲尔邮报

标签 json swift alamofire

我一直在开发一个应用程序,我必须使用 alamofire 来发布。 但是,我不断收到错误,说

失败 错误:反馈提交失败。 可选(“操作无法完成。JSON无法序列化。输入数据为零或零长度。”)

我的代码如下

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。 如有任何帮助,我们将不胜感激。

最佳答案

看来您没有将正确的网址而不是“API”更改传递给帖子的有效网址。

关于json - swift :阿拉莫菲尔邮报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38447292/

相关文章:

swift - 在转到下一个场景之前完成地理编码 swift 3/xcode

ios - 有进度的 Alamofire POST 请求

swift - 如何处理来自可能包含数组或字典的 API 的响应?

json - 从 json 字符串构建 url 时,Alamofire 返回无效的 url

java - 是否有 jackson 注释来抑制不必要的 JSON 包装?

ios - 不需要/未单击的对象自行增加

java - Jackson Unmarshalling 未提供的值

ios - 如何以编程方式为文本添加大纲?

javascript - 在 D3 的情况下,我可以绘制仅包含 json 文件中的链接的图表吗?

c# - 使用 C# 从 json 中反序列化动态对象