怎么样使用Alamofire请求一个JSON数据

iOS 码拜 8年前 (2016-03-25) 1743次浏览
同事搭建了一个WCF,这个WCF接收一个JSON,并会返回一个JSON,他使用安卓已经实现连接。
但本人使用Swift,连接它的时候,POST只能传递字典格式,怎么传JSON格式呢?
本人的代码如下:
let parameters: Dictionary<String,AnyObject> = [“userId”: id,”pwd”:psw]
Alamofire.request(.POST, “http://115.29.41.12:8084/demoService.svc/isUser”, parameters: parameters).responseJSON { ( request, response, JSON, error) in
println(request)
println(response)
println(JSON)
println(error)
}
这个是传递字典格式,返回的结果如下:
怎么样使用Alamofire请求一个JSON数据
本人想POST一个JSON过去怎么弄呢?直接把JSON格式放在parameters出报错类型不符合
解决方案

100

json转字典不是很容易吗?
NSMutableDictionary *dict = [NSMutableDictionary  dictionary];
dict[@”userId”] = id;
dict[@”pwd”] = psw;
let parameters: Dictionary<String,AnyObject> = [“userId”: id,”pwd”:psw]
Alamofire.request(.POST, “http://115.29.41.12:8084/demoService.svc/isUser”, parameters: dict).responseJSON { ( request, response, JSON, error) in
println(request)
println(response)
println(JSON)
println(error)
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样使用Alamofire请求一个JSON数据
喜欢 (0)
[1034331897@qq.com]
分享 (0)