我在java文件中创建了一个JSONOject
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;
}
并且网页上的最终结果如下所示,全部在一行中;
{"Back Door":"Unlocked","Window 2":"Unlocked","Window 3":"Unlocked","Window 1":"Unlocked","Front Door":"Unlocked","System":"Disarmed","Lights":"On"}
(http://finalyearporject.appspot.com/myfirstrestserver)
有没有办法格式化这些数据,以便在列表,子弹或表格格式中显示它。以便最终用户可以阅读?或链接到jsp页面?