我已成功完成对服务器的 POST 请求,我正在尝试解析响应 JSON,但我没有成功。
Alamofire.request(.POST, ServerConfig.ADD_SELLER_URL, parameters: sellerJSON, encoding: .JSON, headers: nil)
.responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in
print(responseRequest!.URL)
print(responseResponse)
print(responseResult)
let json = JSON(responseResponse!)
print(json)
})
我正在使用 SwiftyJSON 进行 JSON 解析。这是我的输出
Optional(http://stage-sellers.strawmine.com/api/v1/sellers/addSeller)
Optional(<NSHTTPURLResponse: 0x7f8f6df20530> { URL: http://stage-sellers.strawmine.com/api/v1/sellers/addSeller } { status code: 400, headers {
Connection = "keep-alive";
"Content-Type" = "application/json; charset=utf-8";
Date = "Mon, 12 Oct 2015 10:32:35 GMT";
Server = "nginx/1.4.6 (Ubuntu)";
"Transfer-Encoding" = Identity;
} })
SUCCESS
unknown
如您所见,仅打印响应标头。另外,如果我打印变量 json,我会得到“未知”。如果我打印 json.stringValue 我得到一个空字符串。我想从正文中获取 JSON 数据。请帮忙!提前致谢!