问题
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