iOS JSONDecoder The data couldn’t be read because it is missing.

在Moya使用Http请求返回的内容

flatMap({ resp -> Observable in

(GroupInfo为我自定义的模型)
出现报错信息

The map data can not to be decode.....

我使用JSONDecoder进行解析也会报错:The data couldn’t be read because it is missing.

原因是jsonData数据里面有个key的值为null了,但是模型里面的这个key是不可选的

解决:
在模型数据吧这个key设置为可选 “?”

*此外还要注意下key的个数是否一致 ,这个参考https://blog.csdn.net/may_he/article/details/83831049

你可能感兴趣的:(iOS JSONDecoder The data couldn’t be read because it is missing.)