如何获得响应值?

时间:2019-01-02 10:11:37

标签: jsonobjectrequest

如何从JsonObjectRequestonResponse函数获得响应?我需要返回插入了现有数据的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();
  }
}); 

0 个答案:

没有答案