Я впервые использую JSON и пытаюсь разобрать файл, а затем переписать его. Это мое письмо в json класс. Тем не менее, я продолжаю получать «Неожиданное ЗНАЧЕНИЕ токена (-3) в позиции 14.» Я смотрел на некоторые другие решения, касающиеся этой топи c, и я просто не понял ответа, а также направил этот ответ на помощь мне решить мою проблему. Если у кого-то есть какая-либо информация по этому поводу, это было бы удивительно.
public class WriteJson {
public static FileWriter file;
@SuppressWarnings("unchecked")
public static void WriteJsonStorage(Task t){
JSONParser jsonParser = new JSONParser();
try {
Object obj = jsonParser.parse(new FileReader("Storage.json"));
JSONArray jsonArray = (JSONArray)obj;
System.out.println(jsonArray);
//Creating local object Task to test in json storage
LocalDate date = t.getDueDate();
String title = t.getTitle();
int importance = t.getImportance();
String desc = t.getDescription();
//Creating a JSONObject object
JSONObject taskDetails = new JSONObject();
//Inserting key-value pairs into the json object
taskDetails.put("Title:", title);
taskDetails.put("Date:", date);
taskDetails.put("Level of Importance:", importance);
taskDetails.put("Description:", desc);
JSONObject taskObject = new JSONObject();
taskObject.put(date, taskDetails);
//putting objects into json array
JSONArray array2 = new JSONArray();
array2.add(taskDetails);
FileWriter file = new FileWriter("Storage.json");
file.write(array2.toJSONString());
file.flush();
file.close();
} catch (ParseException | IOException e) {
e.printStackTrace();
}
}
}