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


i'm using gson project. in particular use code 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 like:

{"cmd":"handshake","arg":{"protocol":"syncmanager","servername":"12345678910"}} 

then on client machine reads 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 jsobj should contain parsed object doesn't contain ( if tostring() prints {} ). why this? want jsonobject tree had on other side, not object serialization. clues?

jsonobject jsobj = new gson().fromjson(cmdstr, jsonobject.class) 

will try , build type of jsonobject string - string isn't.

i think want raw parse tree - can this:

jsonobject jsobj = new jsonparser().parsestring(cmdstr); 

see this more details.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -