Add data to JSONArray

0

I need to add to this result, in each position, some data that I have in json.getJSONObject(l) at the end of the ones I already have.

But according to what I have what it does is replace the data that already exists in datosReserva.getJSONArray("lineas"); the position I choose (l).

This is my code

JSONObject desglosePrecios = obtenerDesglosePrecios(localizador, afilage, usuario.getCodigousu(), usuario.getClausu(), usuario.getAfilusu(), datosReserva.getString("secacc"), datosReserva.getString("integrCamDiv"));
    datosReserva.put("desglosePrecios", desglosePrecios);
    JSONObject obj = datosReserva.getJSONObject("desglosePrecios");
    JSONArray json = obj.getJSONArray("desgloseLineas");
    JSONArray lineas = datosReserva.getJSONArray("lineas");
    JSONArray linea = new JSONArray();
    for (int l = 0; l < lineas.length(); l++) {
            linea.put(json.getJSONObject(l));
            lineas.put(l, linea.getJSONObject(l));
    }

When I add them, replace them:

    
asked by Kat Gar 19.09.2018 в 10:34
source

1 answer

1

I found the solution with:

for (int l = 0; l < lineas.length(); l++) {
        lineas.getJSONObject(l).put("importe_aumentado", json.getJSONObject(l).getString("importe_aumentado"));
        lineas.getJSONObject(l).put("importe_hotel", json.getJSONObject(l).getString("importe_hotel"));
        lineas.getJSONObject(l).put("porcent_iva", json.getJSONObject(l).getString("porcent_iva"));
        lineas.getJSONObject(l).put("ivaInc", json.getJSONObject(l).getBoolean("ivaInc"));
    }

I'll leave it here in case someone needs it later.

    
answered by 19.09.2018 / 17:35
source