Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将参数添加到Alamofire中的请求时出错_Ios_Networking_Parameters_Swift_Alamofire - Fatal编程技术网

Ios 将参数添加到Alamofire中的请求时出错

Ios 将参数添加到Alamofire中的请求时出错,ios,networking,parameters,swift,alamofire,Ios,Networking,Parameters,Swift,Alamofire,我正在使用名为Swift的新网络库进行POST请求 Alamofire允许您单独构建参数格式并添加它。这是我的请求格式 { "DeviceCredentials": { "UniqueId": "sample string 1" }, "Personalnumber": "sample string 1" } 下面是我想到的 let parameters = [ "DeviceCredentials": ["UniqueId": uniqueID], "Pe

我正在使用名为Swift的新网络库进行POST请求

Alamofire允许您单独构建参数格式并添加它。这是我的请求格式

{
  "DeviceCredentials": {
    "UniqueId": "sample string 1"
  },
  "Personalnumber": "sample string 1"
}
下面是我想到的

let parameters = [
    "DeviceCredentials": ["UniqueId": uniqueID],
    "Personalnumber": personalNumber
]
uniqueID
personalNumber
都是字符串类型。我在这一点上没有收到错误,但是当我尝试将其添加到请求中时

Alamofire.request(.POST, "https://www.example.com/api/", parameters: parameters, encoding: .JSON(options: nil)).responseJSON { (request, response, JSON, error) -> Void in
    println(JSON!)
}
我在
参数
参数中得到此错误,'String'与'NSObject'不相同

我的格式有问题吗?或者这是一个bug

谢谢

Edit:我发现用这样的整数(
[“uniqueID”,1]
)替换
uniqueID
)可以消除错误。但我尝试了另一种格式作为测试,我在下面列出了它,它编译时没有任何错误

let paras = [
    "DeviceCredentials": ["UniqueId": uniqueID],
    "UserCredentials": ["Personalnumber": personalNumber]
]
在您的第一个“参数”示例中,字典中有混合类型,而Swift显然无法找出它的推断类型。您可以使用类型批注解决此问题:

let参数:[字符串:AnyObject]=[
“设备标识”:[“唯一标识”:唯一标识],
“Personalnumber”:Personalnumber
]

在你的第二本字典“paras”中,所有类型都是相等的,类型推断成功。

下面的json对我不起作用,任何帮助都会很好让body:Parameters=[“test\u id”:1,“student\u id”:1,“delayed\u mins”:10]