[英]Alamofire, Swift 2.0, SwiftyJSON: Parse response body as JSON
我已經成功完成了對服務器的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數據。 請幫忙! 提前致謝!
您需要使用responseResult.value!
獲取您的json數據。
let json = JSON(responseResult.value!)
print(json)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.