我想要使用alamofire发送到API服务器的长数据,所以我使用SwiftyJSON创建了一个Json对象,现在如果我将json传递给alamofire它会出错,请解释我缺少的内容?
Json:
{
"Skill" : {
"Name" : "iOS",
"Desc" : "Objective-C, Swift"
},
"LangInfo" : [
"Hindi",
"English",
"French",
"Russian"
],
"EduInfo" : {
"Degree" : "MCA",
"School" : "University of Kota",
"Year" : "2013"
},
"GenInfo" : {
"FirstName" : "Varun",
"Email" : "varun@gmail.com",
"State" : "Rajasthan",
"Address" : "Plot No. 00, Bhagwan Nagar 31,",
"Zip" : "21354",
"Phone" : "123456789",
"LastName" : "Sharma"
}
}
代码: -
var jsonObj = JSON(skilldata.data)
println(jsonObj);
let parameters = [
"data": jsonObj
]
Alamofire.request(.POST, BaseUrl+SaveData, parameters: parameters)
.responseJSON { (_, _, JSON, _) in
println(JSON)
let dict:Dictionary<String, String> = JSON as! Dictionary<String, String>
println(dict["status"])
}
此处skilldata.data
为var data = Dictionary<String, AnyObject>()
,错误在.responseJSON { (_, _, JSON, _) in
编辑#1
编辑#2 Xcode版本: - 6.2.3
和
使用pod for Alamofire和SwiftyJson
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '~> 1.2'
pod 'SwiftyJSON', '~> 2.2.0'
答案 0 :(得分:4)
类型 [System.Web.Services.WebMethod(Description = "Get Services Received", EnableSession = true)]
public string getSeviceInformation(string name, string userId, DateTime? newServiceDate, DateTime? newServicesTo, DateTime? renewServiceDate, DateTime? renewServiceTo)
不符合任何对象协议,因此您需要从JSON
获取对象。获取对象参数后,类型将为jsonObj
,仅在此之后,它将满足Alamofire请求的参数类型
[String : AnyObject]