我做了什么:-
1.我想使用AFHTTPSessionManager调用服务
2.我只想使用POST方法以JSON格式传递参数,我也尝试将参数作为JSON传递,但我收到了 错误的请求
3.使用AFNetworking 3.0
我的代码:-
dict = ["email_id":user! , "password": pass!]
do {
jsonData = try NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions.PrettyPrinted)
// here "jsonData" is the dictionary encoded in JSON data
theJSONText = String(data: jsonData!,
encoding: NSASCIIStringEncoding)
print("json string = \(theJSONText)")
} catch let error as NSError {
print(error)
}
manager.POST(urlString, parameters: theJSONText as String!, success:
{
requestOperation, response in
let result = NSString(data: response as! NSData, encoding: NSUTF8StringEncoding)!
print(result)
},
failure:
{
requestOperation, error in
//let result = NSString(data: error as! NSData, encoding: NSUTF8StringEncoding)!
print(error)
})
我想做什么:- 我想将参数作为 JSON 格式传递
Printing description of theJSONText:
"{\n \"email_id\" : \"bbh\",\n \"password\" : \"vh\"\n}"
转换为 JSON STRING 后,我也没有进入 JSON 格式
请帮我这样做..