This code is quite simple
The line:
re = rb.sendRequest("jsonrpc-call=" + JsonHelper.jsoToString(call),
new RequestCallback()
prepare a AJAX call to the server and make your javascript object to a
string using JsonHelper.jsoToString.
In ther server the json-string will be accessible by the parameter
"jsonrpc-call".
The line:
if (response.getStatusCode()
== 200 || response.getStatusCode()
== 304)
{
JavaScriptObject
responseData =
JsonHelper.stringToJso(response.getText()).cast());
// use the response
}
get the response wrote by the server and make i availabe as a
JavaScriptObject.
You can use the JSONObject class to populate and read a
JavaScriptObject.
You can read more about JSON + GWT at:
http://code.google.com/intl/webtoolkit/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideHttpRequests
and
http://code.google.com/intl/webtoolkit/webtoolkit/articles/using_gwt_for_json_mashups.html
On 5 jul, 12:50, Ahmed Shoeib <[email protected]> wrote:
> i want a simple example to describe it
> cause i need it as soon as possible
>
> On Jul 5, 6:18 pm, André Moraes <[email protected]> wrote:
>
>
>
> > re = rb.sendRequest("jsonrpc-call=" +
> > JsonHelper.jsoToString(call),
> > new RequestCallback() {
>
> > @Override
> > public void onResponseReceived(Request
> > request, Response response)
> > {
> > if (response.getStatusCode() == 200
> > || response.getStatusCode()
> > == 304)
> > {
> > JavaScriptObject
> > responseData =
> > JsonHelper.stringToJso(response.getText()).cast());
> > // use the response
> > }
> > else
> > {
> > // invalid response
> > }
> > }
>
> > @Override
> > public void onError(Request request,
> > Throwable exception) {
> > // error on the resquest
> > }
> > });
>
> > public class JsonHelper {
>
> > public static String jsoToString(JavaScriptObject jso) {
> > if (isJsonLibraryDefined()) {
> > return _jsoToString(jso);
> > } else {
> > return new JSONObject(jso).toString();
> > }
> > }
>
> > public static JavaScriptObject stringToJso(String value) {
> > if (isJsonLibraryDefined()) {
> > return _stringToJso(value);
> > } else {
> > return _stringToJsoEval(value);
> > }
> > }
>
> > public static native String _jsoToString(JavaScriptObject jso) /*-{
> > return JSON.stringify(jso);
> > }-*/;
>
> > public static native JavaScriptObject _stringToJso(String string)
> > /*-
> > {
> > return JSON.parse(string);
> > }-*/;
>
> > public static native JavaScriptObject _stringToJsoEval(String
> > string) /*-{
> > return eval("(" + string + ")");
> > }-*/;
>
> > public static native boolean isJsonLibraryDefined() /*-{
> > return typeof(JSON) != 'undefined'
> > && typeof(JSON.parse) != 'undefined'
> > && typeof(JSON.stringify) != 'undefined';
> > }-*/;
>
> > }
>
> > The JsonHelper class handle the conversion to and from JSON.
>
> > If possible use the json.org javascript library that implements the
> > functions JSON.parse / JSON.stringify
>
> > I am currently writing a project that encapsulates that library and
> > make it more easier to use than this JsonHelper class.
>
> > When i release it in google-code I let you know.
>
> > Hope it helps.
>
> > On 5 jul, 09:01, Ahmed Shoeib <[email protected]> wrote:
>
> > > Dear Friends ,
>
> > > i face a problem when trying to send and receive json object between
> > > client and server in GWT application
>
> > > so i want a simple example that show me how to do this
>
> > > Thanks,
> > > ahmed shoeib
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
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.