如何实现此api的改造获取方法,以及如何在Android中使用Java实现模态类?

如何实现此api的改造获取方法,以及如何在Android中使用Java实现模态类?,android,rest,api,retrofit,retrofit2,Android,Rest,Api,Retrofit,Retrofit2,我已经尝试了很多,使模态类,但我陷入了这一点。请帮助我如何为这个Api创建模态类 链接:使用,将您的json粘贴到那里,并选择Java+getter和setter(如果您喜欢)。您可以使用此站点将json转换为POJO。只需复制json对象并将其粘贴到上面,您将得到如下结果: -----------------------------------com.example.Coordinates.java----------------------------------- package com.

我已经尝试了很多,使模态类,但我陷入了这一点。请帮助我如何为这个Api创建模态类

链接:

使用,将您的json粘贴到那里,并选择Java+getter和setter(如果您喜欢)。

您可以使用此站点将json转换为POJO。只需复制json对象并将其粘贴到上面,您将得到如下结果:

-----------------------------------com.example.Coordinates.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Coordinates {

@SerializedName("latitude")
@Expose
private String latitude;
@SerializedName("longitude")
@Expose
private String longitude;

public String getLatitude() {
return latitude;
}

public void setLatitude(String latitude) {
this.latitude = latitude;
}

public String getLongitude() {
return longitude;
}

public void setLongitude(String longitude) {
this.longitude = longitude;
}

}
-----------------------------------com.example.Dob.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Dob {

@SerializedName("date")
@Expose
private String date;
@SerializedName("age")
@Expose
private Integer age;

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

}
-----------------------------------com.example.Example.java-----------------------------------

package com.example;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Example {

@SerializedName("results")
@Expose
private List<Result> results = null;
@SerializedName("info")
@Expose
private Info info;

public List<Result> getResults() {
return results;
}

public void setResults(List<Result> results) {
this.results = results;
}

public Info getInfo() {
return info;
}

public void setInfo(Info info) {
this.info = info;
}

}
-----------------------------------com.example.Id.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Id {

@SerializedName("name")
@Expose
private String name;
@SerializedName("value")
@Expose
private String value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
-----------------------------------com.example.Info.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Info {

@SerializedName("seed")
@Expose
private String seed;
@SerializedName("results")
@Expose
private Integer results;
@SerializedName("page")
@Expose
private Integer page;
@SerializedName("version")
@Expose
private String version;

public String getSeed() {
return seed;
}

public void setSeed(String seed) {
this.seed = seed;
}

public Integer getResults() {
return results;
}

public void setResults(Integer results) {
this.results = results;
}

public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

}
-----------------------------------com.example.Location.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Location {

@SerializedName("street")
@Expose
private String street;
@SerializedName("city")
@Expose
private String city;
@SerializedName("state")
@Expose
private String state;
@SerializedName("postcode")
@Expose
private String postcode;
@SerializedName("coordinates")
@Expose
private Coordinates coordinates;
@SerializedName("timezone")
@Expose
private Timezone timezone;

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getPostcode() {
return postcode;
}

public void setPostcode(String postcode) {
this.postcode = postcode;
}

public Coordinates getCoordinates() {
return coordinates;
}

public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}

public Timezone getTimezone() {
return timezone;
}

public void setTimezone(Timezone timezone) {
this.timezone = timezone;
}

}
-----------------------------------com.example.Login.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Login {

@SerializedName("uuid")
@Expose
private String uuid;
@SerializedName("username")
@Expose
private String username;
@SerializedName("password")
@Expose
private String password;
@SerializedName("salt")
@Expose
private String salt;
@SerializedName("md5")
@Expose
private String md5;
@SerializedName("sha1")
@Expose
private String sha1;
@SerializedName("sha256")
@Expose
private String sha256;

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getSalt() {
return salt;
}

public void setSalt(String salt) {
this.salt = salt;
}

public String getMd5() {
return md5;
}

public void setMd5(String md5) {
this.md5 = md5;
}

public String getSha1() {
return sha1;
}

public void setSha1(String sha1) {
this.sha1 = sha1;
}

public String getSha256() {
return sha256;
}

public void setSha256(String sha256) {
this.sha256 = sha256;
}

}
-----------------------------------com.example.Name.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Name {

@SerializedName("title")
@Expose
private String title;
@SerializedName("first")
@Expose
private String first;
@SerializedName("last")
@Expose
private String last;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getFirst() {
return first;
}

public void setFirst(String first) {
this.first = first;
}

public String getLast() {
return last;
}

public void setLast(String last) {
this.last = last;
}

}
-----------------------------------com.example.Picture.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Picture {

@SerializedName("large")
@Expose
private String large;
@SerializedName("medium")
@Expose
private String medium;
@SerializedName("thumbnail")
@Expose
private String thumbnail;

public String getLarge() {
return large;
}

public void setLarge(String large) {
this.large = large;
}

public String getMedium() {
return medium;
}

public void setMedium(String medium) {
this.medium = medium;
}

public String getThumbnail() {
return thumbnail;
}

public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}

}
-----------------------------------com.example.Registered.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Registered {

@SerializedName("date")
@Expose
private String date;
@SerializedName("age")
@Expose
private Integer age;

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

}
-----------------------------------com.example.Result.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Result {

@SerializedName("gender")
@Expose
private String gender;
@SerializedName("name")
@Expose
private Name name;
@SerializedName("location")
@Expose
private Location location;
@SerializedName("email")
@Expose
private String email;
@SerializedName("login")
@Expose
private Login login;
@SerializedName("dob")
@Expose
private Dob dob;
@SerializedName("registered")
@Expose
private Registered registered;
@SerializedName("phone")
@Expose
private String phone;
@SerializedName("cell")
@Expose
private String cell;
@SerializedName("id")
@Expose
private Id id;
@SerializedName("picture")
@Expose
private Picture picture;
@SerializedName("nat")
@Expose
private String nat;

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public Name getName() {
return name;
}

public void setName(Name name) {
this.name = name;
}

public Location getLocation() {
return location;
}

public void setLocation(Location location) {
this.location = location;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Login getLogin() {
return login;
}

public void setLogin(Login login) {
this.login = login;
}

public Dob getDob() {
return dob;
}

public void setDob(Dob dob) {
this.dob = dob;
}

public Registered getRegistered() {
return registered;
}

public void setRegistered(Registered registered) {
this.registered = registered;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getCell() {
return cell;
}

public void setCell(String cell) {
this.cell = cell;
}

public Id getId() {
return id;
}

public void setId(Id id) {
this.id = id;
}

public Picture getPicture() {
return picture;
}

public void setPicture(Picture picture) {
this.picture = picture;
}

public String getNat() {
return nat;
}

public void setNat(String nat) {
this.nat = nat;
}

}
-----------------------------------com.example.Timezone.java-----------------------------------

package com.example;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Timezone {

@SerializedName("offset")
@Expose
private String offset;
@SerializedName("description")
@Expose
private String description;

public String getOffset() {
return offset;
}

public void setOffset(String offset) {
this.offset = offset;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}
package.com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类坐标{
@序列化名称(“纬度”)
@暴露
私有字符串纬度;
@序列化名称(“经度”)
@暴露
私有字符串经度;
公共字符串getLatitude(){
返回纬度;
}
公共void设置纬度(字符串纬度){
这个。纬度=纬度;
}
公共字符串getLongitude(){
返回经度;
}
公共无效设置经度(字符串经度){
这个经度=经度;
}
}
-----------------------------------com.example.Dob.java-----------------------------------
包com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类Dob{
@序列化名称(“日期”)
@暴露
私有字符串日期;
@序列化名称(“年龄”)
@暴露
私人整数年龄;
公共字符串getDate(){
返回日期;
}
公共无效设置日期(字符串日期){
this.date=日期;
}
公共整数getAge(){
回归年龄;
}
公共无效设置(整数期限){
这个。年龄=年龄;
}
}
-----------------------------------com.example.example.java-----------------------------------
包com.example;
导入java.util.List;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公开课范例{
@SerializedName(“结果”)
@暴露
私有列表结果=null;
@序列化名称(“信息”)
@暴露
私人信息;
公共列表getResults(){
返回结果;
}
公共void setResults(列出结果){
这个结果=结果;
}
公共信息getInfo(){
退货信息;
}
公共无效设置信息(信息){
this.info=info;
}
}
-----------------------------------com.example.Id.java-----------------------------------
包com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类Id{
@序列化名称(“名称”)
@暴露
私有字符串名称;
@序列化名称(“值”)
@暴露
私有字符串值;
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共字符串getValue(){
返回值;
}
公共void设置值(字符串值){
这个值=值;
}
}
-----------------------------------com.example.Info.java-----------------------------------
包com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类信息{
@序列化名称(“种子”)
@暴露
私有串种子;
@SerializedName(“结果”)
@暴露
私有整数结果;
@序列化名称(“页面”)
@暴露
私有整数页;
@SerializedName(“版本”)
@暴露
私有字符串版本;
公共字符串getSeed(){
返回种子;
}
公共无效种子(串种子){
这个种子=种子;
}
公共整数getResults(){
返回结果;
}
公共void setResults(整数结果){
这个结果=结果;
}
公共整数getPage(){
返回页面;
}
公共无效设置页(整数页){
this.page=page;
}
公共字符串getVersion(){
返回版本;
}
公共void setVersion(字符串版本){
this.version=版本;
}
}
-----------------------------------com.example.Location.java-----------------------------------
包com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类位置{
@序列化名称(“街道”)
@暴露
私家弦街;;
@序列化名称(“城市”)
@暴露
私人城市;
@序列化名称(“状态”)
@暴露
私有字符串状态;
@序列化名称(“邮政编码”)
@暴露
私人字符串邮政编码;
@序列化名称(“坐标”)
@暴露
私人坐标;
@序列化名称(“时区”)
@暴露
私人时区;
公共字符串getStreet(){
返回街;;
}
公共街道(字符串街){
这条街;
}
公共字符串getCity(){
回归城市;
}
公共城市(字符串城市){
this.city=城市;
}
公共字符串getState(){
返回状态;
}
公共无效设置状态(字符串状态){
this.state=状态;
}
公共字符串getPostcode(){
返回邮政编码;
}
公共无效设置邮政编码(字符串邮政编码){
this.postcode=邮政编码;
}
公共坐标getCoordinates(){
返回坐标;
}
公共void集合坐标(坐标){
这个。坐标=坐标;
}
公共时区getTimezone(){
返回时区;
}
公共无效设置时区(时区时区){
this.timezone=时区;
}
}
-----------------------------------com.example.Login.java-----------------------------------
包com.example;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类登录{
@序列化名称(“uuid”)
@暴露
私有字符串uuid;
@序列化名称(“用户名”)
@暴露
私有字符串用户名;
@序列化名称(“密码”)
@暴露
私有字符串密码;
@序列化名称(“盐”)
@暴露
私盐;
@序列化名称(“md5”)
@暴露
私有字符串md5;
@序列化名称(“sha1”)
@暴露
私有字符串sha1;
@序列化名称(“sha256”)
@暴露
私有字符串sha256;
公共字符串getUuid(){
返回uuid;
}
公共无效setUuid(字符串uuid){
this.uuid=uuid;
}
公共字符串getUsername(){
返回用户名;
}
public void setUsername(字符串用户名){
this.username=用户名;
}
公共字符串getPassword(){
返回密码;
}
public void setPassword(字符串密码){
this.password=密码;
}
公共字符串getSalt(){
返盐;
}
公共无效设置盐(字符串盐){
盐=盐;
}
公共字符串getMd5(){
复述
public class Example {

@SerializedName("results")
@Expose
private List<Result> results = null;
@SerializedName("info")
@Expose
private Info info;

public List<Result> getResults() {
return results;
}

public void setResults(List<Result> results) {
this.results = results;
}

public Info getInfo() {
return info;
}

public void setInfo(Info info) {
this.info = info;
}

}

public class Coordinates {

@SerializedName("latitude")
@Expose
private String latitude;
@SerializedName("longitude")
@Expose
private String longitude;

public String getLatitude() {
return latitude;
}

public void setLatitude(String latitude) {
this.latitude = latitude;
}

public String getLongitude() {
return longitude;
}

public void setLongitude(String longitude) {
this.longitude = longitude;
}

}

public class Dob {

@SerializedName("date")
@Expose
private String date;
@SerializedName("age")
@Expose
private Integer age;

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

}


public class Id {

@SerializedName("name")
@Expose
private String name;
@SerializedName("value")
@Expose
private String value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}

public class Info {

@SerializedName("seed")
@Expose
private String seed;
@SerializedName("results")
@Expose
private Integer results;
@SerializedName("page")
@Expose
private Integer page;
@SerializedName("version")
@Expose
private String version;

public String getSeed() {
return seed;
}

public void setSeed(String seed) {
this.seed = seed;
}

public Integer getResults() {
return results;
}

public void setResults(Integer results) {
this.results = results;
}

public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

}


public class Location {

@SerializedName("street")
@Expose
private String street;
@SerializedName("city")
@Expose
private String city;
@SerializedName("state")
@Expose
private String state;
@SerializedName("postcode")
@Expose
private String postcode;
@SerializedName("coordinates")
@Expose
private Coordinates coordinates;
@SerializedName("timezone")
@Expose
private Timezone timezone;

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getPostcode() {
return postcode;
}

public void setPostcode(String postcode) {
this.postcode = postcode;
}

public Coordinates getCoordinates() {
return coordinates;
}

public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}

public Timezone getTimezone() {
return timezone;
}

public void setTimezone(Timezone timezone) {
this.timezone = timezone;
}

}

public class Login {

@SerializedName("uuid")
@Expose
private String uuid;
@SerializedName("username")
@Expose
private String username;
@SerializedName("password")
@Expose
private String password;
@SerializedName("salt")
@Expose
private String salt;
@SerializedName("md5")
@Expose
private String md5;
@SerializedName("sha1")
@Expose
private String sha1;
@SerializedName("sha256")
@Expose
private String sha256;

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getSalt() {
return salt;
}

public void setSalt(String salt) {
this.salt = salt;
}

public String getMd5() {
return md5;
}

public void setMd5(String md5) {
this.md5 = md5;
}

public String getSha1() {
return sha1;
}

public void setSha1(String sha1) {
this.sha1 = sha1;
}

public String getSha256() {
return sha256;
}

public void setSha256(String sha256) {
this.sha256 = sha256;
}

}

public class Name {

@SerializedName("title")
@Expose
private String title;
@SerializedName("first")
@Expose
private String first;
@SerializedName("last")
@Expose
private String last;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getFirst() {
return first;
}

public void setFirst(String first) {
this.first = first;
}

public String getLast() {
return last;
}

public void setLast(String last) {
this.last = last;
}

}

public class Picture {

@SerializedName("large")
@Expose
private String large;
@SerializedName("medium")
@Expose
private String medium;
@SerializedName("thumbnail")
@Expose
private String thumbnail;

public String getLarge() {
return large;
}

public void setLarge(String large) {
this.large = large;
}

public String getMedium() {
return medium;
}

public void setMedium(String medium) {
this.medium = medium;
}

public String getThumbnail() {
return thumbnail;
}

public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}

}

public class Registered {

@SerializedName("date")
@Expose
private String date;
@SerializedName("age")
@Expose
private Integer age;

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

}

public class Result {

@SerializedName("gender")
@Expose
private String gender;
@SerializedName("name")
@Expose
private Name name;
@SerializedName("location")
@Expose
private Location location;
@SerializedName("email")
@Expose
private String email;
@SerializedName("login")
@Expose
private Login login;
@SerializedName("dob")
@Expose
private Dob dob;
@SerializedName("registered")
@Expose
private Registered registered;
@SerializedName("phone")
@Expose
private String phone;
@SerializedName("cell")
@Expose
private String cell;
@SerializedName("id")
@Expose
private Id id;
@SerializedName("picture")
@Expose
private Picture picture;
@SerializedName("nat")
@Expose
private String nat;

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public Name getName() {
return name;
}

public void setName(Name name) {
this.name = name;
}

public Location getLocation() {
return location;
}

public void setLocation(Location location) {
this.location = location;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Login getLogin() {
return login;
}

public void setLogin(Login login) {
this.login = login;
}

public Dob getDob() {
return dob;
}

public void setDob(Dob dob) {
this.dob = dob;
}

public Registered getRegistered() {
return registered;
}

public void setRegistered(Registered registered) {
this.registered = registered;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getCell() {
return cell;
}

public void setCell(String cell) {
this.cell = cell;
}

public Id getId() {
return id;
}

public void setId(Id id) {
this.id = id;
}

public Picture getPicture() {
return picture;
}

public void setPicture(Picture picture) {
this.picture = picture;
}

public String getNat() {
return nat;
}

public void setNat(String nat) {
this.nat = nat;
}

}

public class Timezone {

@SerializedName("offset")
@Expose
private String offset;
@SerializedName("description")
@Expose
private String description;

public String getOffset() {
return offset;
}

public void setOffset(String offset) {
this.offset = offset;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}