How can I convert JSONArray to JsArray?

My JsonArray looks like this:

  JSONArray itemsJsonArray = new JSONArray();  
  JSONObject jsobj = new JSONObject();


 jsobj.put("a", new JSONString("hi")); 
 jsobj.put("b", new JSONString("hgjjh")); 
 jsobj.put("c", new JSONNumber(149077));


 itemsJsonArray.set(0, jsobj);

      

I need equivalent data as JsArray (package: com.google.gwt.core.client) as the api I need to use only accepts JsArray.
I need to convert to a specific JsArray, not any JsonObject, and can't take the overhead of serializing my data.

What would be the structure of the equivalent JsArray for the above data, structured as key: value?

+3


source to share


2 answers


This code worked for me.

        JSONArray itemsJsonArray = new JSONArray();  
        JSONObject jsobj = new JSONObject();

        jsobj.put("author", new JSONString("hin")); 
        jsobj.put("text", new JSONString("hgg")); 
        jsobj.put("created", new JSONString("123"));

        itemsJsonArray.set(0, jsobj);

        JavaScriptObject msg =itemsJsonArray.getJavaScriptObject();
        JsArray<?> ob=(JsArray<?>) msg ;

      



Thanks for the help.

+1


source


Edited answer as per your comment:

After looking in the Javadoc for the package you mentioned, maybe try this:



JsArrayMixed jsArray = new JsArrayMixed();
for (int i = 0; i < jsonArray.length(); ++i){ 
   jsArray.push(jsonArray.get(i));
}

      

Remember that you need to parse your object in jsonArray

before JavaScriptObject

.

0


source







All Articles