我如何使用 Retrofit post 这些数据
How can I post these data using Retrofit
我正在尝试 post 我的服务器上的这些数据在我的 android 应用程序上使用改造,但我似乎无法通过如何帮助我谢谢大家
这是我的 APiClient
public interface VerifiedStudentJsonPlaceholder {
@Headers("Content-Type: application/json")
@POST("verifiedStudent")
Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body JsonObject jsonObject);
}
她的是我想要的数据类型 post
{
"firstname":"mutalemwa",
"lastname":"clemence",
"college": "SMCOSE",
"university": "SUA",
"phone": "078989898"
}
很简单。只需为您的请求模型创建一个 class。如下图:
public class Model {
String firstname;
String lastname;
String college;
String university;
String phone;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public String getUniversity() {
return university;
}
public void setUniversity(String university) {
this.university = university;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
然后创建模型的对象并填充它并将其传递给 addVerifiedStudent
方法。不要忘记更改方法签名:
Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body Model model);
我正在尝试 post 我的服务器上的这些数据在我的 android 应用程序上使用改造,但我似乎无法通过如何帮助我谢谢大家
这是我的 APiClient
public interface VerifiedStudentJsonPlaceholder {
@Headers("Content-Type: application/json")
@POST("verifiedStudent")
Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body JsonObject jsonObject);
}
她的是我想要的数据类型 post
{
"firstname":"mutalemwa",
"lastname":"clemence",
"college": "SMCOSE",
"university": "SUA",
"phone": "078989898"
}
很简单。只需为您的请求模型创建一个 class。如下图:
public class Model {
String firstname;
String lastname;
String college;
String university;
String phone;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public String getUniversity() {
return university;
}
public void setUniversity(String university) {
this.university = university;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
然后创建模型的对象并填充它并将其传递给 addVerifiedStudent
方法。不要忘记更改方法签名:
Call<VerifiedStudent> addVerifiedStudent(@Header("Authorization") String token_value, @Body Model model);