Skip to content
Advertisement

JSONObject not giving expected results

I wrote a code of java which adds the data present in array to an existing json file.

This is my code

JavaScript

List<List> list = [[“FileName1″,”Value1″,”Id1”],[],[],[]…] It is writing the code at required path, but not appending it. Previous data gets deleted.

Expected Results

JavaScript

Actual Results

JavaScript

How should i solve this problem ??

Advertisement

Answer

You aren’t collecting your JSONObject idJson = new JSONObject(); before trying to add a new value into it. So each time you open the file, you “erase” the old content.

You can do, subject to the existence of the “system” field (Make sure to check it first).

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement