How to get complex JSON from URL?

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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";


                        }
profilepic.png
manpreet 2 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.