我有一個清潔,簡單的問題,如何閱讀本採用Android改造2.0Android的改造閱讀JSON對象
{
"status": true,
"body": {
"expertises": {
"1": "Family Law",
"2": "Land and Asset",
"3": "Sexual Offense"
}
}
}
我想讀
我已經使用的模型類如下「專長」: 專長:
ExpertisesResponse:
public class ExpertisesResponse {
@SerializedName("1")
private String expertiseOne;
@SerializedName("2")
private String expertiseTwo;
@SerializedName("3")
private String expertiseThree;
public String getExpertiseOne() {
return expertiseOne;
}
public ExpertisesResponse(String expertiseOne, String expertiseTwo, String expertiseThree) {
this.expertiseOne = expertiseOne;
this.expertiseTwo = expertiseTwo;
this.expertiseThree = expertiseThree;
}
public String getExpertiseTwo() {
return expertiseTwo;
}
public String getExpertiseThree() {
return expertiseThree;
}
public void setExpertiseOne(String expertiseOne) {
this.expertiseOne = expertiseOne;
}
public void setExpertiseTwo(String expertiseTwo) {
this.expertiseTwo = expertiseTwo;
}
public void setExpertiseThree(String expertiseThree) {
this.expertiseThree = expertiseThree;
}
}
但我得到了ExceptionisesResposne的Exception NullPointer。 PLease我想要一些改進或更正,如果有任何錯誤。
這是我怎麼叫:
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
Call<Expertises> getExpertises = apiInterface.getExpertise();
getExpertises.enqueue(new Callback<Expertises>() {
@Override
public void onResponse(Call<Expertises> call, Response<Expertises> response) {
Toast.makeText(getApplicationContext(),response.body().getExpertisesResponse().getExpertiseOne(),Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<Expertises> call, Throwable t) {
}
});
}
你創建的模型類該類? – PriyankaChauhan
是的,但如果你能說出來會更好,因爲我對「專家」有困惑 – Danish
專家的數量是否隨時間而變化?這些總是有3個? –