Q:

How to insert one more item in a json existing structure with gson?

The code below generates correctly the first structure of the json file.
gson = new GsonBuilder().setPrettyPrinting().create();

AudDetHeader AudDetHeader = new AudDetHeader();

//ArrayList<OrderDetail> AudDetList = new ArrayList<OrderDetail>();
Map<String, AudDet> AudDetList = new HashMap<String, AudDet>();

AudDet AudDet = new AudDet();
AudDet.setLineId("1");
AudDet.setItemNumber("ABC");
AudDet.setQuantity(9);
AudDet.setPrice(10.00);

List<String> phones = new ArrayList<String>();                   
phones.add("24530001");
phones.add("24530002");
phones.add("24530003");             
AudDet.setPhones(phones);               

AudDetList.put("teste 2", AudDet);              
AudDetHeader.setAudDetList(AudDetList);

Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonString = gson.toJson(AudDetHeader);

BufferedWriter bufferedWriter = null;
try {

    File file = new File(Environment.getExternalStorageDirectory() + "/download/test/test.json");
    if(!file.exists()){
        file.createNewFile();
    }

    FileWriter fileWriter = new FileWriter(file);
    bufferedWriter = new BufferedWriter(fileWriter);
    bufferedWriter.write(jsonString);

} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (bufferedWriter != null){
            bufferedWriter.close();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

The result of the code:
{
  "Results": {
    "teste 2": {
      "itemNumber": "ABC",
      "lineId": "1",
      "phones": [
        "24530001",
        "24530002",
        "24530003"
      ],
      "price": 10.0,
      "quantity": 9
    }
  }
}

I want to add a new item. My desire is to stay as the structure below.
{
   "Results":{
      "teste 2":{
         "itemNumber":"ABC",
         "lineId":"1",
         "phones":[
            "24530001",
            "24530002",
            "24530003"
         ],
         "price":10.0,
         "quantity":9
      },
      "teste 3":{
         "itemNumber":"DEF",
         "lineId":"2",
         "phones":[
            "30303030",
            "40404040",
            "505050"
         ],
         "price":11.0,
         "quantity":12
      }
   }
}

The AudDetHeader.class
public class AuditoriaDetalheHeader {

@SerializedName("Results")
private Map<String, AuditoriaDetalhe> AuditoriaDetalheList;
    ...
}

The AudDet.class
public class AuditoriaDetalhe {

 String lineId = null;
 String itemNumber = null;
 int quantity = 0;
 Double price = null;
 List<String> phones = new ArrayList<String>();
     ...
}

A:

Worked for me with this code!!!
Main class
private static File fileJson = new File(Environment.getExternalStorageDirectory() + "/download/test/test.json");

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.teste_criajson);

createJsonStructure();

Button btnSave = (Button)findViewById(R.id.btSave);

btnSalvar.setOnClickListener( new View.OnClickListener() {
    public void onClick(View v) {

        try {
            String strFileJson = getStringFromFile(fileJson.toString());            
            JSONObject jsonObj = new JSONObject(strFileJson);
            Gson gson = new Gson();
            JsonParser jsonParser = new JsonParser();
            String idAud = "10";

            AudDet ad = new AudDet();
            ad.setLineId("2");
            ad.setItemNumber("DEF");
            ad.setQuantity(22);
            ad.setPrice(22.22);

            List<String> phones = new ArrayList<String>();                   
            phones.add("22");
            phones.add("22");
            phones.add("22");               
            ad.setPhones(phones);       

            String jsonStr = jsonParser.parse(gson.toJson(ad)).toString();
            JSONObject JSONObject = new JSONObject(jsonStr);
            jsonObj.getJSONObject("Results").put(idAud, JSONObject);

            writeJsonFile(fileJson, jsonObj.toString());

        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
});

If do not exists json file, then i create with basic structure for insert the itens.
public static void createJsonStructure(){
    if(!fileJson.exists()){         
        try {
            fileJson.createNewFile();

            String jsonString = "{\"Results\":{}}";

            writeJsonFile(fileJson, jsonString);                

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

Open the json file to get the string format, and prepare to insert a new item:
public static String getStringFromFile (String filePath) throws Exception {
    File fl = new File(filePath);
    FileInputStream fin = new FileInputStream(fl);
    String ret = convertStreamToString(fin);
    //Make sure you close all streams.
    fin.close();        
    return ret;
}
public static String convertStreamToString(InputStream is) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
      sb.append(line).append("\n");
    }
    return sb.toString();
}

Writes into the json file that already exists:
public static void writeJsonFile(File file, String json) 
{
    BufferedWriter bufferedWriter = null;
    try {

        if(!file.exists()){
            file.createNewFile();
        }

        FileWriter fileWriter = new FileWriter(file);
        bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(json);

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bufferedWriter != null){
                bufferedWriter.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

