skip to Main Content

Json – null check is always evaluating to false

import org.json.JSONObject; String someStringJsonData = "{"someKey": " + "null" + "}"; JSONObject someJsonObjectData = new JSONObject(someStringJsonData); Object someKey = someJsonObjectData.get("someKey"); if (null == someKey) { System.out.println("someKey is null"); } I have the above simple snippet of code. I would expect…

VIEW QUESTION

How could I read from an empty json File,at the start of the program is it empty but later can be written

The read file is that: public ArrayList<Aventura> readFile(){ ArrayList<Aventura> aventures = new ArrayList<>(); try{ AventuraDAO aventuraDAO=new AventuraDAO(); AventuraManage aventuraManage=new AventuraManage(aventuraDAO); Gson g=new Gson(); JsonReader reader=new JsonReader(new FileReader("Files/adventures.json")); Aventura[] ave=g.fromJson(reader, Aventura[].class ); if (ave.length==0){ System.out.println("The file should be empty"); ArrayList<Aventura> aventures2…

VIEW QUESTION
Back To Top
Search