【发布时间】:2017-06-21 05:45:04
【问题描述】:
我有 json 数据,我正在使用 gson 转换器解析并响应 pojo 类并显示它。我越来越空了。我已经看到了很多关于这个的问题,但我没有得到太多的解决方案。看看我做错了什么。我是改装新手。
{
"loginj": [
{
"JUser_Id": "20",
"JFullName": "aaa",
"JEmail": "abc@gmail.com"
}
]
}
查看我的改造建造者课程
public static APIInterface getInterfaceService() {
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
final APIInterface mInterfaceService = retrofit.create(APIInterface.class);
return mInterfaceService;
}
模型类
public class Loginj {
private String JUser_Id;
private String JFullName;
private String JEmail;
}
回调类 APIInterface
Call<Loginj> login(@Body User user);
得到响应
Call<Loginj> loginResponseCall = apiInterface.login(user);
loginResponseCall.enqueue(new Callback<Loginj> () {
@Override
public void onResponse(Call<Loginj> call, Response<Loginj> response) {
if (response.isSuccessful()) {
Loginj bodywValue = response.body();
Toast.makeText(getApplicationContext(),""+bodywValue.getJFullName(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Loginj> call, Throwable t){}
【问题讨论】:
-
这里的Loginj是什么?
-
loginj 模型类,所有字段都存在
-
你得到的 Loginj null 对吗?
-
看我的回答,我会工作