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