Serializing JSON object with Alamofire

落爺英雄遲暮 提交于 2020-01-05 05:41:08

问题


Im trying to run to serialize the JSON response, but I am getting an error on the "let json = ..." line. The error is "Ambiguous reference to member 'jsonObject(with:options:)'". If anyone knows how to fix this I will apprechiate it

    Alamofire.request("https://httpbin.org/get").responseJSON { response in

        if let JSON = response.result.value {

            do {
                let json = try JSONSerialization.jsonObject(with: response.result.value!, options: .allowFragments)

            } catch {
                print ()
            }

            print("JSON: \(JSON)")
        }
    }

回答1:


Because response.result.value is type of a dictionary __NSDictionaryI, not a Data as jsonObject expected. You can retrieve value from JSON with ease, no need to convert to json, for example: JSON["title"]



来源:https://stackoverflow.com/questions/40558133/serializing-json-object-with-alamofire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!