WebService의 호출에 대한 응답은 다음과 같습니다.
{
"mobilenumber": "09999999999",
"service": "1" ,
"id": "1"
}
수신 된 Json을 객체로 어떻게 구문 분석합니까?
@Override
public void onResponse(Call<Login> call, Response<Login> response) {
if (response.isSuccessful()) {
}
}
다음 Login
과 같은 모델이 있다고 가정합니다 .
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Login {
@SerializedName("mobilenumber")
@Expose
private String mobilenumber;
@SerializedName("service")
@Expose
private String service;
@SerializedName("id")
@Expose
private String id;
public String getMobilenumber() {
return mobilenumber;
}
public void setMobilenumber(String mobilenumber) {
this.mobilenumber = mobilenumber;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
개조 onResponse()
방법에서 :
@Override
public void onResponse(Call<Login> call, Response<Login> response) {
if (response.isSuccessful()) {
Login loginObject = response.body();
String mobileNumber = loginObject.getMobilenumber();
String service = loginObject.getService();
String id = loginObject.getId();
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다