Working on JSON for the first time. The problem is -
I am getting null pointer exception even after handling the empty json array. I have created a josn file file in which there is an empty array. my json file is like-
{
"name" :"jsonObject",
"myArray" : []
}
For parsing I am using json.simple-1.1.1.jar. My java code is -
JSONParser parser = new JSONParser();
JSONObject rootObj = (JSONObject) parser.parse(new FileReader(filePath));
String str = (String) rootObj.get("name");
JSONArray array = (JSONArray)rootObj.get("array");
if(array.isEmpty())
System.out.println("array is null");
In json file the array will be null sometimes and sometimes not. What is the proper way to handle it?
rootObj.get("myArray")?