0

I get a string from the server that returns the following:

{\"row\" : [{\"name\":\"acb\", \"age\":37}, {\"name\":\"lone\", \"age\":38}]}

and model

public class Row{
    private List<Person> personList;
}
public class Person {
    public String name;
    public int age;
}

So how do I get the item name and age into a class Row and List<Person>.

Give me a way to solve it

Thang
  • 409
  • 1
  • 6
  • 17

1 Answers1

0

You can also use Jackson object mapper to map this json string to your class.

Below is a sample untested code...

import com.fasterxml.jackson.databind.ObjectMapper;

...
...
     
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(yourString).get("row");
    List<Person> output = mapper.readValue(mapper.writeValueAsString(jsonNode), new TypeReference<List<Person>>);