Dinesh2510 / Json-Parse-using-volley

==== JSON Parse with Recyclerview====

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Json-Parse-using-volley

Json Parse

     private void jsonParse() {

    String url = "https://api.myjson.com/bins/kp9wz";

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray jsonArray = response.getJSONArray("employees");

                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject employee = jsonArray.getJSONObject(i);

                            String firstName = employee.getString("firstname");
                            int age = employee.getInt("age");
                            String mail = employee.getString("mail");

                            mTextViewResult.append(firstName + ", " + String.valueOf(age) + ", " + mail + "\n\n");
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    });

    mQueue.add(request);
}