fastjson将json串转成对象时没有空构造器会报错
Fastjson
-
https://github.com/alibaba/fastjson
-
implementation 'com.alibaba:fastjson:1.2.70'
-
解决方式 City.class 在有参构造函数的时候,加入空的构造函数
List listCity =JSONObject.parseArray("key", City.class);
Gson
-
https://github.com/google/gson
-
implementation 'com.google.code.gson:gson:2.8.6'
-
解决方式
-
City.class 对于构造函数无要List listCity = new Gson().fromJson("key", new TypeToken>() { }.getType());
List listCity = new Gson().fromJson("key", new TypeToken>() { }.getType());