Skip to main content

JSONArray to AjaxResult???

1 reply [Last post]
kutlerc
Offline
Joined: 2003-07-09
Points: 0

Below is how I am converting a JSONArray to an AjaxResult. Is this the right way?

<br />
    public void countryService(FacesContext context,<br />
            AjaxResult result) {<br />
        result.setResponseType(AjaxResult.JSON);<br />
        JSONArray countriesData = new JSONArray();<br />
        JSONArray countryData = new JSONArray();<br />
        // simple hack to get some data for this example<br />
        countryData.put("Japan");<br />
        countryData.put("JP");<br />
        countryData.put("Thailand");<br />
        countryData.put("UK");<br />
        countriesData.put(countryData);<br />
        l// Is this the best way to convert to AjaxResult?<br />
        result.append(countriesData.toString());<br />
    }<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi,

This seems like a practical way to emit JSON. I like this because it's simple.