Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:27:35+00:00 2026-05-30T18:27:35+00:00

In the project, I have to send complex JSON commands form the server to

  • 0

In the project, I have to send complex JSON commands form the server to the client. Is it effective to generate JSONObjects ( Strings, Numbers, etc.) convert them to the string and then send them via RequestBuilder or is there a more effective method.

Is it effective to convert JSON objects to string (via the .toString method on the Object)

Code example:

    JSONObject retObject = new JSONObject();
    retObject.put("NumberVar", new JSONNumber(1));
    retObject.put("StringVar", new JSONString("HelloWorld"));

    JSONArray arrayVar= new JSONArray();
    for (int i = 0; i < 5; i++) {
        arrayVar.set(i,
                new JSONString("Array"));
    }
    retObject.put("EventParameters", arrayVar);

    System.out.println(retObject.toString());

Output:

{"NumberVar":1, "StringVar":"HelloWorld", "EventParameters":["Array","Array","Array","Array","Array"]}

Regards,
Stefan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:27:37+00:00Added an answer on May 30, 2026 at 6:27 pm

    The solution you have will work.

    If you want to do it more efficiently, and you only want to support modern browsers with support for JSON.stringify(), you can work in JavaScriptObjects instead of JSONObjects and use this native method:

    private static native String stringify(JavaScriptObject jso) /*-{
      return JSON.stringify(jso);
    }-*/;
    

    Alternatively, you can stringify a JSO by doing:

    String json = new JSONObject(jso).toString();
    

    JavaScriptObjects are more efficient because they are represented in the final compiled code as JS objects, while JSONObjects are represented as emulated Java objects. The second solution will mean less overhead while you construct the JSO, but comparatively more (than the first) when you stringify it.

    Your solution will work just fine though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client that I have to send my ASP.NET project to their
So I have to send a java project to someone outside our company who
In my project there are situations where we have to send xml messages (as
For a particular project I have, no server side code is allowed. How can
I'm dealing with a HTTP sockets project, I have to send 2 HTTP GET
In my project I currently have different models (Project, Message, etc) that: has_many :assets,
I have a project where I made changes, and want to send them to
I have part of a project whereby I need to send 1 to up
I am using centos Server and have to send the mail to the user
I have to send my project to other guy so that he can host

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.