How to write JSON responsePage edited by Cameron McKay
Comment:
Original JSON wasn't valid, added the WebPage class and constructor to make it clearer
Changes (16)
Full ContentIn your WebPage... ... public class JsonWebPage extends WebPage { public JsonWebPage(PageParameters pageParameters) { getRequestCycle().setRequestTarget(new IRequestTarget() { @Override public void detach(RequestCycle requestCycle) { // Nothing to do here. } @Override public void respond(RequestCycle requestCycle) { // Add JSON-encoded string to the response. requestCycle.getResponse().write("{\"jsonKey\":\"jsonValue\"}"); } }); } } ... NOTE: You DO NOT need to manually write JSON response, there are libraries like http://json-lib.sourceforge.net/ available that will allow you to convert an object hierarchy to something more useful in terms of JSON rather easily. For details, check the documentation at: http://json-lib.sourceforge.net/usage.html. Another library for JSON processing/generation is jackson.
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
