Inserting values into a json array at a specific position in java?
<p>I am getting a json array as a string from one activity to the other using intent extras.How can I insert a value at a certain position in the json array in java.
This is the json array that I am using.</p>

<pre><code>{"result":[{"itembarcode":"BRMS","weight":"10","gross_wt":"1","stone_amt":"0","stone_wt":"","rate":"32000","making":"100","qty":"1","net_rate":"32100.0","item_total":"32100.0","sum_total":"64600.0"},
{"itembarcode":"MSAA0015","weight":"10","gross_wt":"11","stone_amt":"100000","stone_wt":"","rate":"32000","making":"500","qty":"1","net_rate":"32500.0","item_total":"32500.0","sum_total":"64600.0"}]}
</code></pre>

<p>And I would like to insert a doc_no inside this array something like </p>

<pre><code>   {"result":[{"doc_no":"IN1001","itembarcode":"BRMS","weight":"10","gross_wt":"1","stone_amt":"0","stone_wt":"","rate":"32000","making":"100","qty":"1","net_rate":"32100.0","item_total":"32100.0","sum_total":"64600.0"},
    {"doc_no":"IN1001","itembarcode":"MSAA0015","weight":"10","gross_wt":"11","stone_amt":"100000","stone_wt":"","rate":"32000","making":"500","qty":"1","net_rate":"32500.0","item_total":"32500.0","sum_total":"64600.0"}]}
</code></pre>

<p>I have tried something like this</p>

<pre><code> try {
            JSONArray jr = new JSONArray(json);
            for (int j=0;j&lt;tot_length; j++)
            {
                JSONObject jb = jr.getJSONObject(j);
                String docnumber = "IN1001";
                jb.put("doc_no",docnumber);
            }
            Log.d("NEW JSON",json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
</code></pre>

<p>But it did not work for me.
Any help or suggestion is appreciated.Thank you.</p>