GSON just to read a JsonObject tree from Json data doesn't work?

Will try and build a type of JsonObject from the string - which your string clearly isn't.

Up vote 2 down vote favorite share g+ share fb share tw.

I'm using GSON for a project. In particular I use this code to generate JSON strings: Gson gs = new Gson(); JsonObject cmdobj = new JsonObject(); cmdobj. AddProperty("cmd", cmd); cmdobj.

Add("arg", args); String cmdstr = cmdobj.toString(); which produces something like: {"cmd":"HANDSHAKE","arg":{"protocol":"syncmanager","serverName":"12345678910"}} then on a client machine this reads the json data: String cmdstr = readCommand(this. Is); Gson gs = new Gson(); JsonObject jsobj = gs. FromJson(cmdstr, JsonObject.

Class); JsonElement cmd = jsobj. Get("cmd"); JsonObject args = jsobj. Get("arg").getAsJsonObject(); the problem is that jsobj that should contain the parsed object doesn't contain anything ( if I do toString() prints {} ).

Why this? I just want the JSonObject tree that I had on the other side, not an object serialization. Any clues?

Gson link|improve this question asked May 10 '11 at 20:41gotch41,638835 66% accept rate.

JsonObject jsobj = new Gson(). FromJson(cmdstr, JsonObject. Class) will try and build a type of JsonObject from the string - which your string clearly isn't.

I think what you want to do is get the raw parse tree - which you can do like this: JsonObject jsobj = new JsonParser(). ParseString(cmdstr); See this for more details.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions