Hi I am using JSON simple library. I have a JSON file like this:
[
"string",
{
...
},
{
...
}
...
]
I have no problem parsing it. But when I finish my application and try to save the changes I cannot add a string to new JSONArray.
JSONArray array = new JSONArray();
array.add("string");
It gives me add(E) in ArrayList cannot be applied to (java.lang.String)
error.
There is no put
method in the JSONArray class.
The solution might be converting JSONObject to JSONArray. But how?
Or could I parse the file and change the contects and then overwrite the original file with it?
Look at the Example 2-1
https://code.google.com/archive/p/json-simple/wikis/EncodingExamples.wiki
EDIT: Using the code below always gives an error. I believe JSONArray object is not intented for encoding. I used a LinkedList instead.
JSONObject obj = new JSONObject();
JSONArray array = new JSONArray();
array.add("string"); // gives error
array.add(obj); // gives error