如何通过 SwiftyJson 和 Alamofire post 嵌套 json?

How to post nested json by SwiftyJson and Alamofire?

如何 post 嵌套 json 作为 SwiftyJson 和 Alamofire 的方法主体?(Swift 3)

{
   "a":{
      "a1": "v1",
      "a2": "v2"
   },
   "b":"bv"
}

我使用 alamofire 在 swift 中检查了很多 post Json post 嵌套对象 如何使用 Alamofire 和 SwiftyJSON 访问嵌套的 JSON 值? Alamofire JSON Serialization of Objects and Collections 和... 但是 none 他们帮助了这种情况。

试试这个

func test()
    {
        var exampleParameters : [String : Any] = ["b" : "bv"]

        exampleParameters["a"] = ["a1": "v1","a2": "v2"]

        debugPrint(exampleParameters.description)

        let devUrlPush = URL.init(string:"yourURL")

        var request = URLRequest(url: devUrlPush!)
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")

        request.httpBody = try! JSONSerialization.data(withJSONObject: exampleParameters)

        Alamofire.request(request).responseJSON { (response) in

            if( response.result.isSuccess)
            {

            }else
            {

            }
        }

        let string = String(data: request.httpBody!, encoding: .utf8)
        let jsonString = JSON(data: request.httpBody!)
        debugPrint(jsonString.rawString(.utf8, options: .prettyPrinted))
        debugPrint(string)
    }

希望对您有所帮助