3

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 the equivalent data as a JsArray (package :com.google.gwt.core.client) since the api that I need to use only accepts the JsArray.
I need to convert to specific JsArray and not any JsonObject and can't take the overhead of serializing my data.

What will be the structure of the equivalent JsArray to the above data structured as key : value ?

JITHIN_PATHROSE
  • 1,134
  • 4
  • 14
  • 29
  • Possible duplicate of [JSON array convert to Javascript array](https://stackoverflow.com/questions/9581623/json-array-convert-to-javascript-array) – daskel Jun 07 '17 at 09:51
  • Something like this https://stackoverflow.com/questions/5618548/convert-json-array-to-javascript-array – Rahul Arora Jun 07 '17 at 09:57

2 Answers2

1

Edited answer according to your comment:

After looking in the Javadoc of 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 you need to parse your object in your jsonArray to JavaScriptObject.

Spitzbueb
  • 5,233
  • 1
  • 20
  • 38
1

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.

JITHIN_PATHROSE
  • 1,134
  • 4
  • 14
  • 29