This way I'm sending html with JSON without problems:
public final class HtmlJSONWrapper extends JavaScriptObject {
public static native HtmlJSONWrapper create(String jsonStr) /*-{
return JSON.parse(jsonStr);
}-*/;
public static native HtmlJSONWrapper create() /*-{
return {}
}-*/;
public final native String getContent() /*-{
return this.htmlContent;
}-*/;
public final native void setContent(String value) /*-{
this.htmlContent = value;
}-*/;
public String toJSONString() {
return new JSONObject(this).toString();
}
}
...
HtmlJSONWrapper htmlWrapper = HtmlJSONWrapper.create();
htmlWrapper.setContent(richTextArea.getHTML());
...
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url);
builder.setHeader("Content-Type", "application/json");
try {
Request response =
builder.sendRequest(htmlWrapper.toJSONString(), requestCallback);
} catch (RequestException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
On Tuesday, November 27, 2012 6:10:11 AM UTC+1, Milan Cvejic wrote:
>
> Hi,
> I am trying to send HTML string to server using RequestBuilder with JSON
> but without any success.
>
> Everything works well when in HTML there are no double quotes or other
> JSON charachters.
>
> So I am trying something like this
>
> RichTextArea area = new RichTextArea();
>
> String htmlToSend = area.getHTML();
>
> JSONObject requestParams = new JSONObject();
> requestParams.put("some_key", new JSONString(htmlToSend));
>
> Unfortunately that string is not encoded properly to be safe to send with
> json
>
> So if value retuned from area.getHTML() contains double quotes like this:
>
> <p><a href="http://www.denic.de/de/domains/recht/index.html"
> target="_blank">www.denic.de/de/domains/recht/index.html</a></p>
>
> request param looks like
>
> {"some_key":"<p><a href="http://www.denic.de/de/domains/recht/index.html"
> target="_blank">www.denic.de/de/domains/recht/index.html</a></p>"}
>
> JSONString method toString() on the other hand is calling
> JsonUtils.escapeValue(value) so that string should be escaped. And If I
> call escapeValue from JsonUtils by myself
> i get string encoded but end up with two double quotes at the beginning
> and the end of that string..
>
> Any help is welcome,
> Thanks,
> Milan
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/u4bBMjFE3a4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.