gpt4 book ai didi

ios - 将长 JSON 响应分配给 Dictionary 会产生线程错误

转载 作者:行者123 更新时间:2023-11-28 09:50:30 24 4
gpt4 key购买 nike

当尝试将长 JSON 响应分配给字典时,我得到了

nil

Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

分配一个简短的回复效果很好。这是我的代码

func getUserInfo() {
let access_token : String = accessToken_json_response["access_token"] ?? "empty"
if access_token != "empty" {
Alamofire.request("https://api.github.com/user?access_token=\(access_token)").responseJSON { response in
if let json = response.result.value {
print(json) //The JSON prints, but takes more than a second to do so.
self.getUser_json_response = json as? Dictionary<String, String> //This produces the thread error when the response is long.
print(self.getUser_json_response) //This either prints nil, or a thread error produces in the previous instruction
}
}
}
}

最佳答案

首先,您要转换为一个可选字典,因此它应该是有条件的绑定(bind),即:

if let unwrappedJson = json as? ....

其次,您应该转换为 [String : Any] 即:

    if let unwrappedJson = json as? [String : Any]

关于ios - 将长 JSON 响应分配给 Dictionary 会产生线程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49276759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com