This is a recurrent problem for me - can I use SwiftyJSON to do this or how?
How can you get the following JSON via .POST with Alamofire :
{
"class":"Class of 1969",
"students":
[
{
"name":"A name",
"age":25
},
{
"name": "B name",
"age": 25
}
]
}
I have the following class:
import UIKit
import SwiftyJSON
class Student{
var Name:String = ""
var Age: Int = 0
}
class StudentsOf1969{
var Teacher: String = ""
var Students = [Student]()
}
Alamofire
Alamofire.request(.POST,
strUrl,
parameters: parameters, // How?????????
encoding: .JSON,
headers: headersWish).responseObject {...
I have tried something like this - adding a var dictionary: [String: AnyObject] to the class:
class Student{
var Name:String = ""
var Age: Int = 0
}
class StudentsOf1969{
var Teacher: String = ""
var Students = [Student]()
var dictionary: [String: AnyObject]{
get {
return [
"teacher": self.Teacher,
"students": self.Students,
// or
"students": [self.Students],
]
}
}
}