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 ?

2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The coding is done in Java and can't take the overhead of making my data to a json string.
My jsonArray has JsonObjects , and is not accepting in push api.
That's why you need JavaScriptObjects and not JsonObject.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.