【发布时间】:2020-11-12 04:37:03
【问题描述】:
我想从响应中获取 ImagePath。
响应如下所示 The response for print(response.result.value)
我正在使用 Alamofire POST 请求从 Api 获取数据。这是我的代码:
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
if response.result.error != nil {
}
let Response = response.result.value
print("Response JSON:- \(String(describing: Response))")
let mydata = (String(describing : Response))
let jSon = JSON(mydata)
print("New :- \(String(describing: jSon["data"]["ImagePath"].stringValue))")
print("New :- \(jSon["data"]["ImagePath"])")
print(jSon["data"]["ImagePath"])
print(jSon["status"].stringValue)
if let data = response.result.value {
let json = JSON(data)
//print(json)
}
}
【问题讨论】:
-
你能做到
print(response.result.value),并在你的问题中添加输出。顺便说一句,您正在将 json 数据转换为字符串格式,然后像 json 一样解析字符串,那是行不通的。 -
print(response.result.value) 的响应是:可选({ data = { ImagePath = "uploadfile/myImages.jpeg"; ThumbImagePath = "uploadfile/thumb/myImages.jpeg"; } ; 状态 = 200; 类型 = 成功; })
-
添加为图片,请查看