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());