swift - 如何获取 JSON 响应并通过它进行解析
问题描述
我正在尝试从 API 获取 JSON 响应,我遇到的问题是我正在尝试解析 JSON,并且一直收到此错误
Cannot subscript a value of type 'String' with an index of type 'String'
这是在我使用 Alamofire 得到回复之后:
AF.request("http://localhost:8080/todos").responseJSON { response in
print(response.description["username"])
}
但是当我尝试使用解析时:
print(response.description["username"])
那是当我最终得到错误时,我想知道我是否做错了什么,或者我错过了一步
解决方案
推荐阅读
- vb.net - 您如何延迟代码以将图像更改为另一个图像,然后返回
- python - Python Beautifulsoup,获取href标签,在标签中
- c# - 两个不同的循环或循环速度比较中的两个条件
- ng-pattern - 在 ng-repeat 中动态设置模式时,ng-pattern 不起作用
- reactjs - 如何向 ctx.renderPage 添加多个样式表?
- reactjs - 在播放视频之前反应原生视频显示缩略图
- ios - SwiftUI - 如何停止 ScrollView 在其他视图后面接收点击
- python - Tkinter treeview 获取 iid python
- mongodb - 如何按嵌入值分组并在mongodb中使用总数为其设置名称
- django - 在 django 中查询畅销产品