I have the following JSON :
{
"user_wallets": [
{
"user_id": "56",
"wallet_id": "25",
"wallet_name": "Dandora Youth Voucher",
"balance": "1,150.00"
},
{
"user_id": "56",
"wallet_id": "36",
"wallet_name": "Pfizer Chama",
"balance": "0.00"
},
{
"user_id": "56",
"wallet_id": "37",
"wallet_name": "Sunshine",
"balance": "1,000.00"
}
]
}
I want to add the wallet_name
and balance
to a list view like this:
wallet_name balance
wallet_name balance
wallet_name balance
and so on. However, I make the http call to my api using volley library but the response shows and empty Toast message.
Where can I be wrong?
The call I am making is this :
public void getMyWallets(){
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try{
JSONArray user_wallets = response.getJSONArray("user_wallets");
for(int i = 0; i<user_wallets.length();i++){
JSONObject wallet = user_wallets.getJSONObject(i);
WalletModel walletModel = new WalletModel();
walletModel.setWallet_name(wallet.getString("wallet_name"));
walletModel.setBalance(((Number) wallet.get("balance")).doubleValue());
walletModelList.add(walletModel);
}
} catch (JSONException e) {
e.printStackTrace();
}
walletListAdapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
hidepDialog();
}
});
MyApplication.getInstance().addToRequestQueue(jsonObjReq);
}