Re: Returning JSON
Re: Returning JSON
- Subject: Re: Returning JSON
- From: Chuck Hill <email@hidden>
- Date: Thu, 18 Jun 2015 15:53:52 +0000
- Thread-topic: Returning JSON
Or consider using ERRest which might be a better solution to your larger need.
Your original code should work (unless something else in the app is chaining this later). But it should be in the page not the Application (otherwise all pages will be marked as json). And that won’t work direct actions (IIRC).
Chuck
On 2015-06-18, 8:48 AM, "Hugi Thordarson" wrote:
Hi Calven.
I’d programmatically create a response and return that, rather than create a separate component . Something like this (warning untested pseudocode):
public WOActionResults downloadJson() {
WOResponse response = new WORespnse();
response.setHeader( “application/json” );
response.setContentString( someStringContainingJSON );
return response;
}
Every JSON parser I have ever encountered defaults to UTF-8 (as they should, it’s part of the RFC) so you shouldn’t have to specify the encoding.
Cheers,
- hugi
// Hugi Thordarson
// s. 895-6688
On 18. jún. 2015, at 15:38, Calven Eggert < email@hidden> wrote:
Hi,
What needs to be done to properly return a webpage with proper json encoding, meaning content type of “application/json"? The page my application is returning seems to be of type “text/html”. I’m not exactly sure how to see what the content
type is. my app returns a WOString with the json text in it. Is this the correct way to handle this?
I’ve found this example but it didn’t seem to make a difference to my app. (In Application.java)
public void appendToResponse(WOResponse response, WOContext context)
{
super.appendToResponse(response, context);
if( _NSUtilities.UTF8StringEncoding.equals(response.contentEncoding()))
response.setHeader("application/json; charset=UTF-8", "Content-Type");
}
Thanks,
Calven
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ( email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden