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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:34:48+00:00 2026-05-13T17:34:48+00:00

public static void parseProfilesJson(String the_json){ try { JSONObject myjson = new JSONObject(the_json); JSONArray nameArray

  • 0
public static void parseProfilesJson(String the_json){
       try {
            JSONObject myjson = new JSONObject(the_json);

            JSONArray nameArray = myjson.names();
            JSONArray valArray = myjson.toJSONArray(nameArray);
            for(int i=0;i<valArray.length();i++)
            {
                String p = nameArray.getString(i) + "," + ValArray.getString(i);
                Log.i("p",p);
            }       

        } catch (JSONException e) {
                e.printStackTrace();
        }
    }

As you can see, this sample code will print out the KEY of the JSONs, followed by the VALUES of the JSONS.

It would print profiles, john if the json was like this:

{'profiles':'john'}

That’s cool. That’s fine, as I can work with those variables. However, what if the JSON was like this:

{'profiles': [{'name':'john', 'age': 44}, {'name':'Alex','age':11}]}

In this case, the entire value would be the array. Basically, I just want to grab that array (which is the “value” in this case)…and turn it into an actual array that JAVA could use. How can I do that? Thanks.

  • 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-13T17:34:48+00:00Added an answer on May 13, 2026 at 5:34 pm

    for your example:

    {'profiles': [{'name':'john', 'age': 44}, {'name':'Alex','age':11}]}
    

    you will have to do something of this effect:

    JSONObject myjson = new JSONObject(the_json);
    JSONArray the_json_array = myjson.getJSONArray("profiles");
    

    this returns the array object.

    Then iterating will be as follows:

        int size = the_json_array.length();
        ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();
        for (int i = 0; i < size; i++) {
            JSONObject another_json_object = the_json_array.getJSONObject(i);
                //Blah blah blah...
                arrays.add(another_json_object);
        }
    
    //Finally
    JSONObject[] jsons = new JSONObject[arrays.size()];
    arrays.toArray(jsons);
    
    //The end...
    

    You will have to determine if the data is an array (simply checking that charAt(0) starts with [ character).

    Hope this helps.

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

Sidebar

Related Questions

public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);
public static void main(String[] args) { staples[] stemp = new staples[8]; int j; try
public static void executeCommand(String cmd) { try { Process process = Runtime.getRuntime().exec(cmd, null, new
public static void Main() { Dictionary<string, double> values = new Dictionary<string, double>(); values.Add(a, 0.002);
public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public class MultiplicationTable { public static void main (String[]a){ int[] x; x = new
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat =
public static void main(String[] args) throws Exception { RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator(); AsymmetricCipherKeyPair
public static void main(String [] a) { String s = new String(Hai); String s1=s;
public class CalendarCal { public static void main(String[] args) { Date date = new

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.