com.google.gson.internal.LinkedTreeMap cannot be cast to entity

問題:
後臺報錯: com.google.gson.internal.LinkedTreeMap cannot be cast to com.xie.Teacher
原因json轉list的時候類型沒寫正確
解決辦法:

import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
Type listType = new TypeToken<List<Teacher>>() {}.getType();
        List<Teacher> list=JsonUtil.fromJson(jsonStr, listType);
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i).getName());
        }

        String jsonResult=JsonUtil.toJson("");
        return jsonResult;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章