Question

I've made a JSONOject in a java file

public String handleGet() {
try {
JSONObject system = new JSONObject();

system.put("System", "Disarmed");
system.put("Front Door", "Unlocked");
system.put("Back Door", "Unlocked");
system.put("Window 1", "Unlocked");
system.put("Window 2", "Unlocked");
system.put("Window 3", "Unlocked");
system.put("Lights", "On");

JsonRepresentation jsonRep = new JsonRepresentation(system);

return jsonRep.getText();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}

and the end result on the webpage look like this, all in one line;

{"Back Door":"Unlocked","Window 2":"Unlocked","Window 3":"Unlocked","Window 1":"Unlocked","Front Door":"Unlocked","System":"Disarmed","Lights":"On"}

( http://finalyearporject.appspot.com/myfirstrestserver )

Is there any way to format this data to show it in a list, or bullet pointed or in a table format ect. so that it could be readable to an end user? Or link to a jsp page?

Was it helpful?

Solution

You can use gson from Google. It has a pretty print feature for user-friendly JSON format. GSON

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top