【发布时间】:2018-05-13 01:23:45
【问题描述】:
我正在尝试在recyclerview 中使用volley 在android 中解析Json Array,但它显示的数据少于服务器上的数据。
我的意思是它只解析 4 个数据,服务器有 10 个。为什么?
代码:
JsonObjectRequest jsonObjectReq = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject data, deal_mode;
String total, ref, name,category_name,start_date,end_date,offer_price,market_price,gain,structure_note,other_note;
data = resp.getJSONObject("data");
total = data.getString("total");
JSONArray data1 = data.getJSONArray("data");
try {
for (int i = 0; i <response.length(); i++) {
JSONObject jresponse = data1.getJSONObject(i);
ref = jresponse.getString("ref");
name = jresponse.getString("name");
deal_mode = jresponse.getJSONObject("deal_mode");
category_name=deal_mode.getString("category_name");
start_date=jresponse.getString("start_date");
end_date=jresponse.getString("end_date");
offer_price=jresponse.getString("offer_price");
market_price=jresponse.getString("market_price");
gain=jresponse.getString("gain");
structure_note=jresponse.getString("structure_note");
other_note=jresponse.getString("other_note");
Toast.makeText(getApplication(), name, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(getApplication(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
//This is for Headers
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json; charset=UTF-8");
params.put("Authorization", "Bearer" + getToken);
return params;
}
};
//Add the Request to the RequestQueue.
VolleySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectReq, REQUEST_TAG);
【问题讨论】:
-
你的代码在哪里...???
-
Dinesh 请发布您的代码以便更好地参考
标签: android arrays json android-recyclerview android-volley