-1
"fid": "123",
"farm_info": {
    "name": "Example Farm",
    "address": "Example Address",
    "phone": "111-111-1111",
    "web": ""
},
"personal_info": {
    "name": "MyName",
    "email": "myname@example.com",
    "phone": "111-111-0000"
},
"delivers_to": ["60001", "60002"]

This is an object returned as JSON. In JAVA fid would be a String and delivers_to would be an Array of strings. What data type would farm_info and personal_info be to have this JSON returned?

K96
  • 1
  • 1

1 Answers1

1

A class is a custom defined data type in Java (you can define the group of elements like structure in C) and so, farm_info and personal_info are Object types.

So to parse your JSON, along with the data types you mentioned, you need the below custom defined datatypes (Java Classes).

public class FarmInfo {
     private String name;
     private String address;
     private String phone;
     private String ;web

     //Getter and Setter methods need to be generated
}

public class  PersonalInfo {
    private String name;
    private String email;
    private String phone;
    //Getter and Setter methods need to be generated
}

You can refer here for more about Classes and objects.

Also, refer here for understanding JSON parsing.

Vasu
  • 21,832
  • 11
  • 51
  • 67