How to get complex JSON from URL?

Course Queries Syllabus Queries 3 years ago

3.53K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago

 

 

My json is like this

{
    "results": [{
        "syllabus": "CBSE",
        "grade": "5",
        "subject": "Kannada",
        "topic": "Grammar Level 1",
        "id": 28
    }]
}

Using Volley

         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);

                            System.out.println(person.toString());





                            String syllabus = person.getString("syllabus");
                            String grade= person.getString("grade");
                            jsonResponse += "Name: " + syllabus + "\n\n";
                            jsonResponse += "Email: " + grade + "\n\n";


                        }
0 views
0 shares

profilepic.png
manpreet 3 years ago

Your Json have an object and then array.. tag/try">try like this

JsonObjectRequest req = new JsonObjectRequest(urlJsonArry,

            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
        Log.d(TAG, response.toString());

              tag/try">try {
          JSONOArray array = response.getJSONArray("tag/results">results") 
                    // Parsing json array response
                    // loop through each json object
                    jsonResponse = "";
                    for (int i = 0; i < array.length(); i++) {

                        JSONObject person = (JSONObject) array
                                .get(i);

                        System.out.println(person.toString());

                        String syllabus = person.getString("syllabus");
                        String grade= person.getString("grade");
                        jsonResponse += "Name: " + syllabus + "\n\n";
                        jsonResponse += "Email: " + grade + "\n\n";


                    }

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum