How to convert JSON string into List of Java object?

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

This is my JSON Array :-

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


        
9条回答
  •  长情又很酷
    2020-12-01 12:26

    You can also use Gson for this scenario.

    Gson gson = new Gson();
    NameList nameList = gson.fromJson(data, NameList.class);
    
    List list = nameList.getList();
    

    Your NameList class could look like:

    class NameList{
     List list;
     //getter and setter
    }
    

提交回复
热议问题