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 8761975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:24:53+00:00 2026-06-13T15:24:53+00:00

I have tried to run following code Gson gson = new Gson(); String json

  • 0

I have tried to run following code

Gson gson = new Gson();
String json = gson.toJson(result);
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("sEcho", echo);
jsonResponse.put("iTotalRecords", iTotalRecords);
jsonResponse.put("iTotalDisplayRecords", iFilteredTotalRecords);
jsonResponse.put("aaData", json);
jsonResponse.toString();

JSONArray data = new JSONArray();
for (Object obj : result) {
    JSONArray row = new JSONArray();
    User user = (User) obj;
    row.put(user.getId()).put(user.getUserName()).put(user.isEnabled());
    data.put(row);
}
JSONObject jsonResponse2 = new JSONObject();
jsonResponse2.put("sEcho", echo);
jsonResponse2.put("iTotalRecords", iTotalRecords);
jsonResponse2.put("iTotalDisplayRecords", iFilteredTotalRecords);
jsonResponse2.put("aaData", data);
jsonResponse2.toString();

The result from toString function for both jsonResponse are as follows:

{"iTotalDisplayRecords":11,"iTotalRecords":11,"aaData":"[{\"creationTime\":0,\"enabled\":true,\"id\":1,\"loginDuration\":0,\"online\":false,\"password\":\"asda\",\"userName\":\"abiieez\"}]","sEcho":"1"}

{"iTotalDisplayRecords":11,"iTotalRecords":11,"aaData":[[1,"abiieez",true]],"sEcho":"1"}

I would like to eliminate the ” symbol before [ and after ] from the first json response just like the second one (I noticed that the ” is added after the array being put to the jsonResponse object). How can I accomplish this ?

  • 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-06-13T15:24:54+00:00Added an answer on June 13, 2026 at 3:24 pm

    Since you first convert your “result” to a String, and then add it to aaData, it will end up quoted, like a String should. If all you’d like to do is to remove the quotes, you could do something like this in line 2:

    String json = "##" + gson.toJson(result) + "##";
    

    and this in line 8:

    jsonResponse.toString().replace("\"##", "").replace("##\"","");
    

    (of course you need to choose the “quote marker” ## such that it will never appear as actual string content in your data anywhere else)

    But the cleaner solution (although probably slower) would likely be to convert your String to an actual JSONObject by changing line 2 to:

    JSONObject json = new JSONObject(gson.toJson(result));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to run the following code, as a proof of concept, and
I have tried the following code .. btnRemoveItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View
Following the README instructions of the jboss-as-kitchensink example , I have tried to run
I tried to run the following code from http://docs.python.org/library/mmap.html import mmap # write a
I've tried to run the following code on my PC. With PORT 0x378 (LPT1
I have the following code....and I can't seem to get the ads to run
I have run the following code in this page RsyntaxTextArea using Java and i
Every time I run the following code, it keeps on saying Input string was
I can't seem to run the following code in Eclipse. I do have a
I have tried to get the output of following code but its giving out

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.