I am new in android, and I'm usig retrofit
.
The problem is that I can't obtain my POJO
from request.
my request is:
@FormUrlEncoded
@POST("/index.php")
void login(@Field("io") String command,
@Field("lu") String userName,
@Field("lp") String password,
@Field("lm") String imei,
@Field("l") int language,
RestCallback<ModelLoginResponse> callback);
server JSON response is:
{
"tk": "thdoz4hwer32",
"pn": "1",
"lc": {
"1": "Opel Combo",
"3": "VW Crafter",
"7": "Opel Vivaro"
},
"stg": {
"rs": "30",
"sml": "http://exemple.mob.ru",
"ssl": "index.php"
}
}
where 1,3,7 are different every time
and my POJO class:
@Parcel
public class ModelLoginResponse {
@SerializedName("pn")
private String personalNumber;
@SerializedName("tk")
private String token;
// ?????? for "lc" and "stg"
public void ModelResponse(String personalNumber, String token){
this.personalNumber = personalNumber;
this.token = token;
}
public String getPersonalNumber() {
return personalNumber;
}
public void setPersonalNumber(String personalNumber) {
this.personalNumber = personalNumber;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
How should I complete my ModelLoginResponse
POJO class for obtaining full server response???
Try to define your ModelLoginResponse class in this way:
If to parse the JSON string, you use the GSON library you need only a default constructor without arguments and every "field" of the JSON string needs his corresponding attribute in the target class.