如何从JsonObjectRequest
,onResponse
函数获得响应?我需要返回插入了现有数据的id
:
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray arr = new JSONArray(response);
for (int i = 0;i < arr.length(); i++) {
JSONObject jObj = arr.getJSONObject(i);
strVal = String.valueOf(jObj.getInt("id"));
Log.d("OutPut", jObj.getString("id"));
}
} catch (JSONException e) {
e.printStackTrace();
}
// pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
//pDialog.hide();
}
});