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

Questions:

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

    System.out.println(obj);
    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];
        is.read(buffer);
        is.close();
        json = new String(buffer, "UTF-8");


    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return json;
}
Answers: