我尝试使用
JSONDecodable
但失败了。
我创建了一个自定义类并用扩展
Decodable
.
class CustomError: Decodable {
// Properties
var errors: [String: [String:String]]?
var message: String?
}
并使用以下行对返回的
nil
:
let jsonError = try? JSONDecoder().decode(CustomError.self, from: data!)
但我得到以下结果
JSONSerialization
:
let jsonError = try? JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
结果:
Optional({
errors = {
email = (
"The email has already been taken."
);
};
message = "The given data was invalid.";
})
为什么
可剥的
不起作用?