1
這對我來說是一個經常性問題 - 我可以使用SwiftyJSON來做到這一點或如何?Alamofire參數與類中的數組
你怎麼能透過.POST得到下面的JSON與Alamofire:
{
"class":"Class of 1969",
"students":
[
{
"name":"A name",
"age":25
},
{
"name": "B name",
"age": 25
}
]
}
我有下面的類:
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 {...
我已經試過這樣的事情 - 將一個變種dictionary: [String: AnyObject]
到類:
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],
]
}
}
}
太感謝你了!我很早就錯過了$ 0.dictionary。對! –