Эй, тебе нужно добавить ниже классов
public class Address {
@SerializedName("street")
@Expose
private String street;
@SerializedName("suite")
@Expose
private String suite;
@SerializedName("city")
@Expose
private String city;
@SerializedName("zipcode")
@Expose
private String zipcode;
@SerializedName("geo")
@Expose
private Geo geo;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getSuite() {
return suite;
}
public void setSuite(String suite) {
this.suite = suite;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public Geo getGeo() {
return geo;
}
public void setGeo(Geo geo) {
this.geo = geo;
}
}
Фирменный класс
public class Company {
@SerializedName("name")
@Expose
private String name;
@SerializedName("catchPhrase")
@Expose
private String catchPhrase;
@SerializedName("bs")
@Expose
private String bs;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCatchPhrase() {
return catchPhrase;
}
public void setCatchPhrase(String catchPhrase) {
this.catchPhrase = catchPhrase;
}
public String getBs() {
return bs;
}
public void setBs(String bs) {
this.bs = bs;
}
}
Geo Class
public class Geo {
@SerializedName("lat")
@Expose
private String lat;
@SerializedName("lng")
@Expose
private String lng;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
}
Тестовый класс
public class TestModel {
@SerializedName("id")
@Expose
private String id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("username")
@Expose
private String username;
@SerializedName("email")
@Expose
private String email;
@SerializedName("address")
@Expose
private Address address;
@SerializedName("phone")
@Expose
private String phone;
@SerializedName("website")
@Expose
private String website;
@SerializedName("company")
@Expose
private Company company;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
}
Замените приведенный ниже код на свой код
@ Примечание. Замените mJsonArray на класс ответа
ArrayList<TestModel> listdata = new ArrayList<TestModel>();
JSONArray mJsonArray = new JSONArray();
//Replace mJsonArray to response
for(int i=0; i<mJsonArray.length(); i++) {
try {
JSONObject json = mJsonArray.getJSONObject(i); //First object
String id = json.getString("id");
String name = json.getString("name");
String username = json.getString("username");
String email = json.getString("email");
String phone =json.getString("phone");
String website =json.getString("website");
JSONObject json2 = json.getJSONObject("address"); //Second object
String street = json2.getString("street");
String suite = json2.getString("suite");
String city = json2.getString("city");
String zipcode = json2.getString("zipcode");
JSONObject json3 = json2.getJSONObject("geo");
String lat = json3.getString("lat");
String lang = json3.getString("lng");
JSONObject json4 = json.getJSONObject("company");
String companyName = json4.getString("name");
String catchPhrase = json4.getString("catchPhrase");
String bs = json4.getString("bs");
TestModel model = new TestModel();
model.setId(id);
model.setName(name);
model.setUsername(username);
model.setEmail(email);
model.setPhone(phone);
model.setWebsite(website);
Address mAddress = new Address();
mAddress.setStreet(street);
mAddress.setSuite(suite);
mAddress.setCity(city);
mAddress.setZipcode(zipcode);
Geo mGeo = new Geo();
mGeo.setLat(lat);
mGeo.setLng(lang);
mAddress.setGeo(mGeo);
model.setAddress(mAddress);
Company company = new Company();
company.setBs(bs);
company.setCatchPhrase(catchPhrase);
company.setName(companyName);
model.setCompany(company);
listdata.add(model);
} catch (JSONException e) {
e.printStackTrace();
}
}
if(listdata.size()>0){
//Hope you need pass list to MyAdapter
listView.setAdapter(new Myadapter()); //Custom Adapter
}