How to convert JSON string into List of Java object?

前端 未结 9 2217
醉酒成梦
醉酒成梦 2020-12-01 12:12

This is my JSON Array :-

[ 
    {
        \"firstName\" : \"abc\",
        \"lastName\" : \"xyz\"
    }, 
    {
        \"firstName\" : \"pqr\",
        \"         


        
9条回答
  •  佛祖请我去吃肉
    2020-12-01 12:27

    Try this. It works with me. Hope you too!

    List testList = new ArrayList<>();
    testList.add(test1);
    
    Gson gson = new Gson();
    
    String json = gson.toJson(testList);
    
    Type type = new TypeToken>(){}.getType();
    
    ArrayList array = gson.fromJson(json, type);

提交回复
热议问题