How can I get the value of device (SE_S2) or status using JSONObject class?
String body = '{"device":"SE_S2","status":"1","time":"1524737618.66301","status":"ON"} '
JSONObject root = new JSONObject(body);
How can I get the value of device (SE_S2) or status using JSONObject class?
String body = '{"device":"SE_S2","status":"1","time":"1524737618.66301","status":"ON"} '
JSONObject root = new JSONObject(body);
It won't work, because you have a duplicate key ("status"). If you remove that, you'd be able to get the device by doing:
String body = "{\"device\":\"SE_S2\",\"status\":\"1\",\"time\":\"1524737618.66301\"}";
JSONObject root = new JSONObject(body);
System.out.println(root.get("device"));
Try like below:-
JSONObject root = new JSONObject(body);
String device = root.get("device").toString();
For json {\"device\":\"SE_S2\",\"status\":\"1\",\"time\":\"1524737618.66301\"}
Note that you have multiple element with the same key 'status' which is not allowed.