首页 > 解决方案 > 如何获取 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"])

那是当我最终得到错误时,我想知道我是否做错了什么,或者我错过了一步

标签: swiftalamofire

解决方案


推荐阅读