How to convert JSONArray to List with Gson?

后端 未结 1 908
难免孤独
难免孤独 2020-12-03 16:42

In my Android project I\'m trying to convert a received JSONArray to a List. With the help of this SO answer I got a bit further. I now have the following code:



        
1条回答
  •  醉话见心
    2020-12-03 17:07

    If you see the answer there, you can notice that the first parameter in the fromJson() method was a String(the json object). Try to use the toString() on the JsonArray like this:-

    List myModelList = gson.fromJson(jsonArray.toString(), listType);
    

    0 讨论(0)
提交回复
热议问题