0
please tell me I am new to use JSON data. Thanks in Advance.

https://api.myjson.com/bins/waw4y

how to parse this data in android. I am adding the two client details. In that 
First, I have added an object for the whole content and after I have added the different client names and age, car with arrays. so please make it as easy. 
Thanks in advance 

JSON stands for JavaScript Object Notation. It is an independent data exchange format and is the best alternative for XML. This chapter explains how to parse the JSON file and extract necessary information from it.

Android provides four different classes to manipulate JSON data. These classes are JSONArray,JSONObject,JSONStringer and JSONTokenizer.

The first step is to identify the fields in the JSON data in which you are interested in. For example. In the JSON given below we interested in getting 
temperature only.
Mahendhar
  • 7
  • 5
  • Possible duplicate of https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java. Please take a look to see if it helps you solve your problem. – TEK292 Jul 25 '18 at 18:29
  • No, This is only in multiple arrays – Mahendhar Jul 25 '18 at 18:34
  • GSON is library from Google its helps you for your situations : [using GSON](https://stackoverflow.com/questions/5490789/json-parsing-using-gson-for-java) – Amjad Alwareh Jul 25 '18 at 18:56
  • The number of arrays has no bearing on the solution. Converting the string to JSON is covered in that question. The accepted answer tells you how to get the values from a JSONArray and a JSONObject. – TEK292 Jul 25 '18 at 19:06
  • I checked your json, and it's not complicated. I did an example of JSOn using the github api on a YouTube video. Hope this really helps you. https://youtu.be/Pl4dG5FkDfQ – Madona wambua Jul 25 '18 at 19:09
  • Your JSON does not seem compatible to parse in a dynamic way, You need to re-design the JSON. I am attaching a code snippet hope it will help you. – Hardik Vegad Jul 25 '18 at 19:26

1 Answers1

0

This code is not feasible with dynamic implementation of JSON, Just to showcase the Parsing proccess.

JSONObject client = null;
    try {
        client = new JSONObject(response);
        JSONArray clientChild1 = client.getJSONArray("client1");
        JSONArray clientChild2 = client.getJSONArray("client2");
        for (int j = 0; j < clientChild1.length(); j++) {
            JSONObject objectChild = clientChild1.getJSONObject(j);
            Log.e("NAME", "onCreate: " + objectChild.getString("name"));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
Hardik Vegad
  • 111
  • 1
  • 7