-4
我試圖從下面的JSON得到temp_max的價值,但我得到null.Also得到迴應,我能得到鱈魚,消息和CNT的值。
我正在使用「」response.body()。getTempMax()「」來獲取值。讓我知道如果這不是正確的方式。
Model類
公共類主要{
@SerializedName("temp_min")
@Expose
private Double tempMin;
@SerializedName("temp_max")
@Expose
private Double tempMax;
public Double getTempMin() {
return tempMin;
}
public void setTempMin(Double tempMin) {
this.tempMin = tempMin;
}
public Double getTempMax() {
return tempMax;
}
public void setTempMax(Double tempMax) {
this.tempMax = tempMax;
}
}
}
MainActivity
ApiInterface apiInterface = ApiClient.getClient()創建(ApiInterface.class)。
Call<Main> call = apiInterface.getWeather();
call.enqueue(new Callback<Main>()
{
@Override
public void onResponse(Call<Main> call, Response<Main> response)
{
response.body();
Toast.makeText(MainActivity.this, "The cnt is " + response.body().getTempMax(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<Main> call, Throwable t)
{
Log.e("Main", t.toString());
}
});
你能粘貼代碼爲您解析類以及 – MRX