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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:47:11+00:00 2026-05-23T10:47:11+00:00

How do you convert this String into gson.JsonArray? String s= [[110917 , 3.0099999999999998, -0.72999999999999998,

  • 0

How do you convert this String into gson.JsonArray?

String s= "[["110917    ", 3.0099999999999998, -0.72999999999999998, 2.8500000000000001, 2.96, 685.0, 38603.0], ["110917    ", 2.71, 0.20999999999999999, 2.8199999999999998, 2.8999999999999999, 2987.0, 33762.0]]";

This is my Code:

 com.google.gson.*;
 public static void main(String[] args)
   {
       //Declared S here
       System.out.println("String to Json Array Stmt");
       JsonParser parser = new JsonParser();
       JsonElement tradeElement = parser.parse(s.toString());
       JsonArray trade = tradeElement.getAsJsonArray();
       System.out.println(trade);
    }

Is this the way to convert this Collections string to JSonArray?

  • 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-23T10:47:11+00:00Added an answer on May 23, 2026 at 10:47 am

    To have a string value inside your JSON array, you must remember to backslash escape your double-quotes in your Java program. See the declaration of s below.

    String s = "[[\"110917       \", 3.0099999999999998, -0.72999999999999998, 2.8500000000000001, 2.96, 685.0, 38603.0], [\"110917    \", 2.71, 0.20999999999999999, 2.8199999999999998, 2.8999999999999999, 2987.0, 33762.0]]";
    

    Your code in the main() method works fine. Below is just a minor modification of your code in the main() method.

    System.out.println("String to Json Array Stmt");
    JsonParser parser = new JsonParser();
    JsonElement tradeElement = parser.parse(s);
    JsonArray trade = tradeElement.getAsJsonArray();
    System.out.println(trade);
    

    Lastly, remember to prefix your statement “com.google.gson.*” with the keyword “import”, as shown below.

    import com.google.gson.*;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to convert this string into DateTime. Tue Aug 19 15:05:05 +0000 2008
I have a simple String abc = réunion; I should convert this string into
How can I convert this string into XML? string sTemp = <message> <Category> <Category
Hey looking to convert this string into datetime 20101119T162837 And then also how to
What can I use to convert this string into a number? "$148,326.00" I am
I create a string: myOption = "{val1:'text1', val2:'text2'...}" I need convert this string into
How do I convert this string -> string = [{name:sam}] into a python dictionary
How to convert this string $parent = 2011-08-04 15:00:01; to separate it into two
I need to convert this string into a hex color: '0.047,0.380,0.247,0.900'. It is labeled
I'd like to convert this string into a datetime object: Wed Oct 20 16:35:44

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.