【发布时间】:2020-02-26 01:28:16
【问题描述】:
我托管了一个 json 文件 -> http://cipherads.co.in/api/bbps/billerinfo.php
我需要获取所有“billerId”字段。我正在使用 Volley 发出 GET 请求并遍历对象。但我面临一个问题,我的日志只显示前两个“billerId”值。我该如何解决这个问题?
String urlJsonObj = "http://cipherads.co.in/api/bbps/billerinfo.php";
private void makeJsonObjectRequest() {
//showpDialog();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
urlJsonObj, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Log.d(TAG, response.toString());
try {
JSONArray biller = response.getJSONArray("biller");
Log.d(TAG, biller.toString());
// Loop through biller Array and find billerID
for (int i = 0; i < response.length(); i++)
{
JSONObject billerID = (JSONObject) biller.get(i);
String id = billerID.getString("billerId");
Log.d(TAG, id);
}
Toast.makeText(getApplicationContext(), biller.toString(), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
【问题讨论】:
标签: android json android-volley