Java POJO的JSON对象数组




arrays object (2)

将此JSON对象转换为java中的类,映射将如何在您的POJO类中?

{
    "ownerName": "Robert",
    "pets": [
        {
            "name": "Kitty"
        },
        {
            "name": "Rex"
        },
        {
            "name": "Jake"
        }
    ]
}

在你的json中你拥有 ownerName 作为属性, pets 作为对象列表

public class Response {

  private String ownerName;

  private List<Pet> pets;

  // getters and setters
  }

宠物POJO

public class Pet {

 private String name;

 //getters and setters

  }

您可以使用以下类:

public class MyObject {
    private String ownerName;
    private List<Pet> pets;
}

public class Pet {
    private String name;
}




object