Answer the question
In order to leave comments, you need to log in
GSON - How to declare variables to store names from complex JSON?
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "[email protected]",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
},
]
public class GetGeo {
private int id;
private String name;
private String username;
private String email;
private Object address;
}
Answer the question
In order to leave comments, you need to log in
There is such a site - www.jsonschema2pojo.org
On the site you will also find a maven plugin for quick conversion
-----------------------------------com.example.Address.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Address {
@SerializedName("street")
@Expose
public String street;
@SerializedName("suite")
@Expose
public String suite;
@SerializedName("city")
@Expose
public String city;
@SerializedName("zipcode")
@Expose
public String zipcode;
@SerializedName("geo")
@Expose
public Geo geo;
}
-----------------------------------com.example.Company.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Company {
@SerializedName("name")
@Expose
public String name;
@SerializedName("catchPhrase")
@Expose
public String catchPhrase;
@SerializedName("bs")
@Expose
public String bs;
}
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("id")
@Expose
public int id;
@SerializedName("name")
@Expose
public String name;
@SerializedName("username")
@Expose
public String username;
@SerializedName("email")
@Expose
public String email;
@SerializedName("address")
@Expose
public Address address;
@SerializedName("phone")
@Expose
public String phone;
@SerializedName("website")
@Expose
public String website;
@SerializedName("company")
@Expose
public Company company;
}
-----------------------------------com.example.Geo.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Geo {
@SerializedName("lat")
@Expose
public String lat;
@SerializedName("lng")
@Expose
public String lng;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question