1

I have been working with JSONP on my GWT application. When my server sends a json string, I can get it in the form of a JavaScriptObject on the client side.

My problem is my json has complicated structures: using maps, nests with a lot of different keys. That is a big pain to extract data (I may have to write few hundred functions for all keys to extract data one by one and some complicated codes to fill maps).

I am considering few solutions:

  • Encode and send whole json strings as normal strings to client (as a value of a simple json string). Just worry my encoded strings may be few time longer than the original ones and may easily exceed the limit of 2k long

  • Convert back a JavaScriptObject into a pure string (similar to one I sent from the server)

After having a pure string I will parse it using some json parsers / methods to the structures I feel convenient.

My questions:

1) How to convert back a JavaScriptObject object into a pure / original json string?

2) Any idea about solutions?

Many thanks

1 Answer 1

1

1) Convert JavaScriptObject to JSON: JsonUtils.stringify(yourJSO)
Convert JSON to JavaScriptObject: JsonUtils.safeEval(jsonString);

2) Did you think about using AutoBeans?? Check out the GWT page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.