我正在使用 Retrofit2 从 MySQL 数据库中获取数据列表。我想将所有获取的数据放入 android 中的 RecyclerView 但响应不成功。我Call<Loan>一开始做了,它返回了一个响应,但我的适配器只接受列表数组,所以我将其更改为Call<List<Loan>>但现在响应不成功。我做了一个邮递员请求,它返回了数据,所以我不知道我哪里做错了。fetchLoans 方法public void fetchLoans(String key){ final Call<List<Loan>> loanCall = ApiClient .getInstance() .getApi() .fetchLoans(key); loanCall.enqueue(new Callback<List<Loan>>() { @Override public void onResponse(Call<List<Loan>> call, Response<List<Loan>> response) { if (response.isSuccessful()) { if (response.body() != null) { Log.i("onSuccess", response.body().toString()); progressBar.setVisibility(View.GONE); List<Loan> loanList = response.body(); loanAdapter = new LoanAdapter(context, loanList); recyclerView.setAdapter(loanAdapter); loanAdapter.notifyDataSetChanged(); } else { progressBar.setVisibility(View.GONE); Toast.makeText(context, "No loans at the moment" + response.body().toString(), Toast.LENGTH_SHORT).show(); } }else{ progressBar.setVisibility(View.GONE); Toast.makeText(context, "Request failed", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(Call<List<Loan>> call, Throwable t) { progressBar.setVisibility(View.GONE); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); } });}我的 API 方法@GET("Loans/fetch_loan.php?")Call<List<Loan>> fetchLoans( @Query("keyWord") String keyWord);当我在 Postman 中发出请求时返回的内容。获取贷款请求
添加回答
举报
0/150
提交
取消