I am trying to convert a String to Json Array (without name/tag) and iterate through the resultant array.. But the resultant json array is shown as null when I debug the code. I cant find the cause of this issue.
Below is the given string that I am trying to parse into a Json Array.
String jsonString="[ {"
+ "\"TimeStamp\": \"20:10\","
+ "\"PipeTemp\": \"31.5\","
+ "\"ChocolateMixingTemp\": \"25\","
+ "\"WaterCoolingTemp\": \"5\","
+ "\"WaterMixingTemp\": \"0\","
+ "\"WaterHeatingTemp\": \"0\",},
+{"
+ "\"TimeStamp\": \"20:00\","
+ "\"PipeTemp\": \"35.5\","
+ "\"ChocolateMixingTemp\": \"28\","
+ "\"WaterCoolingTemp\": \"3\","
+ "\"WaterMixingTemp\": \"15\","
+ "\"WaterHeatingTemp\": \"0\","
+}]";
I pass the above string to Java Array instance and then iterate it using for loop to generate a PDF Table. But I see that Json Array is shown as null when I try to check its size.
JSONArray jsonArray = new JSONArray(jsonString);
JSONObject jsonObject;
for(int n = 0; n < jsonArray.length(); n++)
{
table.addCell(createCell( (String) jsonObject.get("TimeStamp"),Element.ALIGN_CENTER));
table.addCell(createCell( (String) jsonObject.get("PipeTemp"),Element.ALIGN_CENTER));
table.addCell(createCell( (String) jsonObject.get("ChocolateMixingTemp"), Element.ALIGN_CENTER));
table.addCell(createCell( (String) jsonObject.get("WaterCoolingTemp"),Element.ALIGN_CENTER));
table.addCell(createCell( (String) jsonObject.get("WaterMixingTemp"),Element.ALIGN_CENTER));
jsonObject.get("WaterHeatingTemp"),Element.ALIGN_CENTER));
}
Can someone please help me identify why the array is shown as empty? I also tried to test with a simple string containing of only two key-value pairs. But got the same result.
WaterHeatingTemp.