PDA

View Full Version : JsonConverter does not decode JSON?



tmcguire
3 Feb 2010, 4:57 PM
When calling JsonConverter.decode(s), the JSON string s does not seem to be read correctly. Specifically, JsonConverter seems to discard the first two characters of value strings:


{"menu":[{"heading":"one","href":"one/"}]}produces a Map with the expected structure but that looks like it comes from the JSON:


{"menu":[{"heading":"e","href":"e/"}]}Looking at JsonConverter.java, it seems to be expecting some kind of type tag at the beginning of the string, but that does not conform to any JSON (http://www.json.org/) grammar (http://www.ietf.org/rfc/rfc4627.txt)I've seen.

cabster
9 Mar 2010, 2:41 AM
Yes i have the same problem. Is this a bug or are we doing something wrong?

sven
9 Mar 2010, 2:48 AM
JsonConverter needs an own format. It should not be used in a general case. This kind of tag is needed to support any java dataformat you might want to support.

cabster
11 Mar 2010, 3:16 AM
JsonConverter needs an own format. It should not be used in a general case. This kind of tag is needed to support any java dataformat you might want to support.

What shall i use then? I now encode my json with 2 extra spaces infont of the value;


result.put("message", " " + result.get("message"));

and decoded like this:


Map<String, Object> result = JsonConverter.decode(jsonStr);

sven
11 Mar 2010, 3:19 AM
There is no buildin class for your usecase. GWT offers JSONObject you can use.

tmcguire
11 Mar 2010, 7:52 AM
What shall i use then?

The standard GWT JSONParser (http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/json/client/JSONParser.html) correctly parses JSON.