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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:43:10+00:00 2026-05-17T01:43:10+00:00

[I have some code to create a JSON array. In this code I am

  • 0

[I have some code to create a JSON array. In this code I am passing some values to x, y, z in a loop which looks like this.

   JSONArray list = new JSONArray();
   String jsonText = null;
   for (int j = 0; j < 4; j++) {
       list.add(new Integer(x));
       list.add(new Integer(y));
       list.add(new Integer(z));
       jsonText = list.toString();
  }
  System.out.print(jsonText);

This gives output as

[1234,245,10,312,234,122,1234,67788,345,235,001,332]

How can I get these values in a single array like this?

[[1234,245,10],[312,234,122],[1234,67788,345],[235,001,332]]

] I got the answer for this question needs answer for the below question.

I used one of the below solutions.
Thanks for the response from you guys.

Now i got JSON formate nested Arrays which looks like this

[
[[1234,245,10],[312,234,122],[1234,67788,345],[235,001,332]],
[[1234,245,10],[312,234,122],[1234,67788,345],[235,001,332],[1234,67788,3450]],
[[1234,245,10],[312,234,122],[1234,67788,345],[235,001,332],[1234,67788,34534]]]

SO i have One big Array which contains three arrays(this can be 2 or more than three arrays sometimes) and each of these three array contains some arrays, in this above example

what is the reverse procedure ? i mean what if i want those values from these arrays. In the same way how i have did. using JSON
JSONArray list = new JSONArray();
list.get() this get method will give me what i requies ?
I used the org.json Java API.

Thanks friends for helping me till now.

  • 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-17T01:43:11+00:00Added an answer on May 17, 2026 at 1:43 am

    I suspect what you want is a syntactically correct JSON array of nested arrays of integers (original post requests invalid JSON). If not, go with @BalusC’s answer.

    To get an array containing sub-arrays, simply create the sub-arrays as int[] arrays, and add them directly to your main JSONArray.

    public int[] getThreeValues() { // example
        Random r = new Random();
        return new int[] { r.nextInt(100), r.nextInt(100), r.nextInt(100) };
    }
    
    public void execute() {
    
        JSONArray master = new JSONArray();
    
        for (int j=0; j<4; j++) {
            master.put(getThreeValues());
        }
    
        System.out.println(master);
    }
    

    Result:

    [[3,13,37],[24,4,64],[61,2,1],[97,13,86]]

    Note: I’m not sure which JSON library your using, so I used the org.json Java API, which uses put(...) rather than add(...). Also, that particular library supports adding int[] arrays directly to JSONArray – yours may not, in which case you’d need to build the nested JSONArrays and add them to your master.

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

Sidebar

Related Questions

I have an array that gets created from JSON. The array looks like this:
I have a JSON array like this [{Email:someone@some.com,Name:ACO,Groups:[MOD_SW,MOD_PI,MOD_GE],Id:63,Url:aco}, {Email:someone@some.com,Name:Agpo,Groups:[MOD_PI],Id:22,Url:agpo}, {Email:someone@some.com,Name:Akatherm,Groups:[MOD_SW],Id:64,Url:akatherm}, {Email:someone@some.com,Name:Albrand,Groups:[MOD_PI,MOD_GE],Id:23,Url:albrand}] I want to
I have been writing some code to create a byte array I will be
I have JSON array created having code like user_images.push({'href' : value.href, 'title' : value.title
In my application I have the array, which create in Main_View_Controller from json response
I have some code to create a basic dialog box with several options -
we have some C++ code that we need to create a make file in.
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
I have some simple .NET objects I'd like to serialize to JSON and back
I have some problems with this code? Here is my code that creates text

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.