我正在尝试将一组自定义类型内联到dir中 - 作为Alamofire的参数。 Alamofire在'Invalid type in JSON write
ParameterEncoding.swift: Line142
失败
case .JSON:
do {
let options = NSJSONWritingOptions()
let data = try NSJSONSerialization.dataWithJSONObject(parameters, options: options) // 'Invalid type in JSON write
MyClass的
class MyClass{
var name: String = ""
var address: String = ""
}
这给出了错误:
class MyParameters{
var MyClasses: [MyClass] = []
var dictionary: [String: AnyObject]{
get {
return [
"myclasses": self.MyClasses,
]
}
}
}
尝试了这个from:
class MyClass{
var name: String = ""
var address: String = ""
}
class MyParameters{
var MyClasses: [MyClass] = []
var dictionary: [String: AnyObject]{
get {
return [
"myclasses": self.MyClasses.map({$0.name}),
]
}
}
}