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 <ahmedelsayed.sho...@gmail.com> 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 google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to