GSON parse generic Json Array

后端 未结 3 1061
暖寄归人
暖寄归人 2020-12-21 23:18

My question is very similiar to this: Unable to parse Json array using Gson

But I cann\'t get the answer from it. The answer from above link:

public         


        
3条回答
  •  -上瘾入骨i
    2020-12-22 00:00

    you can do like this:

         Gson gson = new Gson();
    
        String jsonString = "[{\"id\":18,\"city\":\"test\",\"street\":\"test 1\",\"zipcode\":121209,\"state\":\"IL\",\"lat\":32.158138,\"lng\":34.807838},{\"id\":19,\"city\":\"test\",\"street\":\"1\",\"zipcode\":76812,\"state\":\"IL\",\"lat\":32.161041,\"lng\":34.810410}]";
    
        List tmpList = gson.fromJson(jsonString);
        List resultList = new Arraylist(tmplist.size());
        for(Map map:tmpList){
           String tmpJson = gson.toJson(map);
           resultList.add(gson.fromJson(tmpJson, classT));
        }
        return resultList;
    

提交回复
热议问题