Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void makeJsonArrayRequest() {
- showpDialog();
- JsonArrayRequest req = new JsonArrayRequest(urlJsonArry,
- new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- Log.d(TAG, response.toString());
- try {
- // Parsing json array response
- // loop through each json object
- jsonResponse = "";
- for (int i = 0; i < response.length(); i++) {
- JSONObject person = (JSONObject) response
- .get(i);
- String name = person.getString("name");
- String email = person.getString("email");
- JSONObject phone = person
- .getJSONObject("phone");
- String home = phone.getString("home");
- String mobile = phone.getString("mobile");
- jsonResponse += "Name: " + name + "\n\n";
- jsonResponse += "Email: " + email + "\n\n";
- jsonResponse += "Home: " + home + "\n\n";
- jsonResponse += "Mobile: " + mobile + "\n\n\n";
- }
- txtResponse.setText(jsonResponse);
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(getApplicationContext(),
- "Error: " + e.getMessage(),
- Toast.LENGTH_LONG).show();
- }
- hidepDialog();
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- VolleyLog.d(TAG, "Error: " + error.getMessage());
- Toast.makeText(getApplicationContext(),
- error.getMessage(), Toast.LENGTH_SHORT).show();
- hidepDialog();
- }
- });
- // Adding request to request queue
- AppController.getInstance().addToRequestQueue(req);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement