Home » Android » **Recovering** data from JSON and **putting it back with** new info

**Recovering** data from JSON and **putting it back with** new info

Posted by: admin November 1, 2017 Leave a comment


I have a problem when I want to recover info from a JSON and I want to add more info.

The fact is that I have an app that I’m developing where I want to add people to a Json with some data related to people.

I have the Class People with the data to fill up, but I can’t get the info of all the JSON I have in RAW and add another person. After that, I’d like to add it all to the JSON again.

Could you help me please?

Right now I have this: (But I’m lost)

public void getStringofFormerJson(String json) throws IOException, JSONException {

    JSONObject obj = new JSONObject(json);

    Toast.makeText(this, "Hay: " + obj.toString(), Toast.LENGTH_SHORT).show();


public String backearJsonYAnadir()

    //Lo primero que hay que hacer es coger los datos del json

    String json = null;
    try {

        InputStream is = getResources().openRawResource(Integer.parseInt("pacientes.json"));

        int size = is.available();
        byte[] buffer = new byte[size];
        json = new String(buffer, "UTF-8");

    } catch (IOException ex) {
    return json;