在android

时间:2017-04-26 06:57:21

标签: android json retrofit2

//get user and password form JSONArray
public void loginapi(){
    String username = user.getText().toString();
    String password = passwd.getText().toString();

    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);

    Call<List<Akses>> call = apiService.getEmployeeAkses(donat, username, password);
    call.enqueue(new Callback<List<Akses>>() {
        @Override
        public void onResponse(Call<List<Akses>> call, Response<List<Akses>> response) {
            String waduser,wadpass;
            ArrayList<Akses> aksesList = new ArrayList<Akses>();
            waduser = aksesList.get(0).getUsername().toString();
            wadpass = aksesList.get(0).getPassword().toString();
        }

        @Override
        public void onFailure(Call<List<Akses>> call, Throwable t) {
            Log.e("Errore : ", t.getMessage());
            Toast.makeText(getApplicationContext(), "Terjadi Kesalahan masalah API", Toast.LENGTH_SHORT);
        }
    });

}

如何使用代码获取JSONArray?

  

waduser = aksesList.get(0).getUsername()。toString();   wadpass = aksesList.get(0).getPassword()。toString();

记录上面的代码时,它不会产生任何结果。 我该怎么办?

1 个答案:

答案 0 :(得分:4)

试试这个

Int->Int