最佳答案
我想用 Alamofire 发布一条关于一具尸体的信息。
我的 Json 身材看起来像:
{
"IdQuiz" : 102,
"IdUser" : "iosclient",
"User" : "iosclient",
"List":[
{
"IdQuestion" : 5,
"IdProposition": 2,
"Time" : 32
},
{
"IdQuestion" : 4,
"IdProposition": 3,
"Time" : 9
}
]
}
我正在尝试使 let
list
与 NSDictionary 看起来像:
[[Time: 30, IdQuestion: 6510, idProposition: 10], [Time: 30, IdQuestion: 8284, idProposition: 10]]
而我使用 Alamofire 的请求看起来像:
Alamofire.request(.POST, "http://myserver.com", parameters: ["IdQuiz":"102","IdUser":"iOSclient","User":"iOSClient","List":list ], encoding: .JSON)
.response { request, response, data, error in
let dataString = NSString(data: data!, encoding:NSUTF8StringEncoding)
println(dataString)
}
该请求有一个错误,我相信问题是与字典列表,因为如果我提出了一个请求,没有列表它工作正常,所以有什么想法?
我试过建议的解决办法,但我面临着同样的问题:
let json = ["List":list,"IdQuiz":"102","IdUser":"iOSclient","UserInformation":"iOSClient"]
let data = NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted,error:nil)
let jsons = NSString(data: data!, encoding: NSUTF8StringEncoding)
Alamofire.request(.POST, "http://myserver.com", parameters: [:], encoding: .Custom({
(convertible, params) in
var mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
mutableRequest.HTTPBody = jsons!.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
return (mutableRequest, nil)
}))
.response { request, response, data, error in
let dataString = NSString(data: data!, encoding:NSUTF8StringEncoding)
println(dataString)
}