I am trying to convert a file that contains data logging parameters to be json format.
Currently it retains the format:
{ X }
{ X }
I know this is not a valid JSON format, so I am trying to make it like this:
[
{ X },
{ X }
]
This is the code I have right know that logs data as this function is called:
public void write(String _rec) {
writeLock.writeLock().lock();
timestamp = System.currentTimeMillis();
String jsonstr = "{ \"timestamp\":" + timestamp + ", \"record\" : " + _rec + " },\n";
// Log.d(LOG_TAG, jsonstr);
try {
fileWriter.write(jsonstr);
fileWriter.flush();
} catch(IOException e) {
e.printStackTrace();
}
writeLock.writeLock().unlock();
} // END write
I added the comma in after the closing }, but I am not sure what to do about the []. Is there a way when I make the file I can insert the [] and then start writing information between them? Is there another solution to automatically insert these brackets?