fastjson將json串轉成對象時沒有空構造器會報錯

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

     

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章