I have long data that I want send to API server with alamofire so I created a Json object with SwiftyJSON and now if I pass the json to alamofire it gives an error please explain what I am missing ?
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" : "[email protected]",
"State" : "Rajasthan",
"Address" : "Plot No. 00, Bhagwan Nagar 31,",
"Zip" : "21354",
"Phone" : "123456789",
"LastName" : "Sharma"
}
}
Code :-
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"])
}
Here skilldata.data
is var data = Dictionary<String, AnyObject>()
and the error is on the line .responseJSON { (_, _, JSON, _) in
Edit #1
Edit #2 Xcode ver :- 6.2.3
and
Using pod for Alamofire and SwiftyJson
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Alamofire', '~> 1.2'
pod 'SwiftyJSON', '~> 2.2.0'
Type
JSON
does not conform to any object protocol so you will need to get object fromjsonObj
. After getting object parameters type will be[String : AnyObject]
and only after that, it will meet parameter type of Alamofire request