-5
"data": [
    {
        "Id": 1,
        "Schoolid": 0,
        "Name": "1",
        "Section": "A",
        "CreatedOn": null
    },
    {
        "Id": 2,
        "Schoolid": 0,
        "Name": "1",
        "Section": "B",
        "CreatedOn": null
    },
    {
        "Id": 3,
        "Schoolid": 0,
        "Name": "1",
        "Section": "C",
        "CreatedOn": null
    },
    {
        "Id": 4,
        "Schoolid": 0,
        "Name": "2",
        "Section": "A",
        "CreatedOn": null
    },
    {
        "Id": 5,
        "Schoolid": 0,
        "Name": "2",
        "Section": "B",
        "CreatedOn": null
    },

] }

From this JSON response, I want to name 1 section separate and next, name sections separate and set in recycler view in android

For example:

name 1 ---A,B,C name 2 -- A,B name 3 -- A,B,C,D

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Gaurav sappal
  • 81
  • 1
  • 5
  • Could you explain what you want to do a little better? I don't understand the meaning of what you said. – tomerpacific Dec 13 '18 at 07:20
  • 1
    follow this link : https://www.androidhive.info/2016/01/android-working-with-recycler-view/ – Ali Dec 13 '18 at 07:20
  • first, you can convert your json response to POJO, http://www.jsonschema2pojo.org/ become something like this https://gist.github.com/rosdyana/59c9b67817c3efe656c6cc845536c2cd, then you continue with create an adapter for your recycleview, handler, and everything to complete according to @Ali's link. – taipei Dec 13 '18 at 07:29
  • Possible duplicate of [How do I parse JSON in Android?](https://stackoverflow.com/questions/9605913/how-do-i-parse-json-in-android) – Vladyslav Matviienko Dec 13 '18 at 07:29
  • https://medium.com/@peterekeneeze/parsing-remote-json-to-recyclerview-android-1ad927e96d58 try this. – rak Dec 13 '18 at 07:33
  • I want name wise sections @tomerpacific – Gaurav sappal Dec 13 '18 at 07:34

1 Answers1

0
 public void parseJson(String jsonString) {
String strJson = jsonString;
    try {
        JSONArray data = new JSONArray(strJson);
        ArrayList<Student> studentList = new ArrayList<>();
        for (int i = 0; i < data.length(); i++) {
            Student student = new Student();
            student.setId(data.getJSONObject(i).getInt("Id"));
            student.setName(data.getJSONObject(i).getString("Name"));
            student.setSection(data.getJSONObject(i).getString("Section"));
            student.setCreatedOn(data.getJSONObject(i).getString("CreatedOn"));

            studentList.add(student);
        }

        // Here you can use student list
        Log.d("Students", studentList.toString());

    } catch (JSONException e) {
        e.printStackTrace();
    }
}


// This is pojo class of students which can be used to store student object
public class Student {
    int id;
    String name;
    String section;
    String createdOn;

    public Student() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        this.section = section;
    }

    public String getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(String createdOn) {
        this.createdOn = createdOn;
    }
}
Sanjay Kushwah
  • 190
  • 1
  • 9