import Credentials.UserCredentials; import Files.WriteFile; import JSON_Unpack.ReadSensors4Partner; import Knowledgebase.SensorReadings; import org.json.JSONArray; import org.json.JSONObject; import java.lang.reflect.Array; import java.util.ArrayList; public class ApiCall { private static String token = "0"; private static String oldId = "1"; public static String FetchDataFromApi(String extension) throws Exception { UserCredentials userCredentials = new UserCredentials(); final String username = userCredentials.getUsername(); final String password = userCredentials.getPassword(); final String homeRoot = userCredentials.getHomeRoot(); String outputToken; WriteFile writingIntoFile = new WriteFile(); if (token.equals(oldId)) { //do nothing } else { try { outputToken = SecurityToken.OnCallMethod(username, password); JSONObject obj = new JSONObject(outputToken); token = obj.getString("id"); writingIntoFile.WriteFile(homeRoot+"securityToken.txt", token); oldId = token; } catch (Exception e) { e.printStackTrace(); } } ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner(); SensorReadings sensorReadings = new SensorReadings(); String outputValue = (readSensors4Partner.FetchSensor4Box("Germes",token)); System.out.println(outputValue); String outputValueFixed=outputValue.replace("[[","[") +outputValue.replace("[{","{")+outputValue.replace("}]","}")+ outputValue.replace("]]","]"); System.out.println(outputValueFixed); JSONArray jsonArray = new JSONArray(outputValueFixed); System.out.println(jsonArray.length()); for(int j=0; j