发送参数以请求Swift 3 Alamofire

时间:2017-01-12 11:08:42

标签: swift alamofire

嗨,我是新来的,我遇到了Swift 3和Alamofire的问题。我必须发送这个值,但是我收到了一个错误。我想我应该做那种不同的方式,但我找不到,你能帮助我吗?

  

错误:上下文类型' [字符串:任意]'不能与数组一起使用   字面

let url: String = "http://192.168.1.1/ubus"
    let param: [String: Any] = ["{ \"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"call\", \"params\": [ \"00000000000000000000000000000000\", \"session\", \"login\", { \"username\": \"root\", \"password\": \"admin01\"  } ] }" ]
    Alamofire.request(url, method: .post, parameters: param,
                      encoding: JSONEncoding.default)
        .responseJSON { response in
            if(response.result.isFailure){
                print("no data!");

            }else{
                print("received data!");
            }
    }

1 个答案:

答案 0 :(得分:2)

要解决此问题,请尝试了解如何正确地为请求形成params Dictionary

在你的情况下,你在params有问题。

修正版:

let param: [String: Any] = ["jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", [ "username": "root", "password": "admin01"]]]