JITHIN_PATHROSE
JITHIN_PATHROSE

Reputation: 1396

Convert a Javascript object to a Json object without serializing

I have a java-script object (com.google.gwt.core.client.JavaScriptObject). I need to convert the data in this object into a JSONObject (com.google.gwt.json.client.JSONObject). How can I do this?.

I have tried this:

JavaScriptObject object=getData();

String json=stringfy((JsArray) object);  //done using native JSNI method

JSONValue jsonValue=null;

jsonValue=JSONParser.parseStrict(json);

JSONObject  msg=jsonValue.isObject();

The problem here is that I need to serialize and make a json string out of my data which is an overhead. Is there any other method to do this ?

Upvotes: 0

Views: 322

Answers (1)

Ignacio Baca
Ignacio Baca

Reputation: 1578

JavaScriptObject object = getData();
JSONObject msg = new JSONObject(object);

Upvotes: 2

Related Questions