ios - 从 alamofire 获取数据 (responseString)
问题描述
我正在使用此代码检索数据
Alamofire.request(urlString, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: headers)
.responseString() { response in
switch response.result {
case .success(let data):
let jsonData = JSON(data)
print(jsonData)
case .failure(let error):
print("\(error) - hello world")
}
}
服务器发送的结果是
{"result":"Opertion is successfull"}
但我只想要价值部分"Opertion is successfull"
解决方案
使用 almofire文档中的代码
Alamofire.request(urlString, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: headers)
.responseString() { response in
if let jsonData = response.result.value {
print("JSON: \(jsonData)") // serialized json response
}
}
推荐阅读
- python - 在 Dockerfile 中设置非 root 用户并安装 pip 包
- xaml - StackLayout Tableview 截断半屏,但仅在发布模式下
- git - 有没有办法用用于 rebase 的列表预先提供 git rebase
- css - 使用 CSS 将宽度设置为 100% 时,是否可以将高度设置为宽度的百分比
- java - 如何解决安装 Spring Book 项目后在 pom.xml 文件中出现的此错误?
- google-apps-script - 使用脚本将时间/日期数据从一个谷歌表导入另一个谷歌表时的时间/日期问题
- neo4j - 查询检查节点中的所有源状态是否已完成?
- regex - Data Studio Regex (Google RE2) 从路径中提取子目录
- mongodb - 按国家/地区划分的类型“戏剧”的电影数量
- python-3.x - 从熊猫列中提取特定值并将其存储在新列中