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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:08:12+00:00 2026-06-11T21:08:12+00:00

I have tried parsing JSON for the first time. In my JSON data there

  • 0

I have tried parsing JSON for the first time. In my JSON data there are multiple JSON objects in a single JSON array. The data sample:

{ “root”:[ {“Sc_we”:[ ]}, {“Sc_wesam”:[ {“head”:”Welcome page”}, {“color”:”Black”} ]} ] }

This is my code:

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        website = new URL(
                    "http://xxxxxxx");
        InputStream in = website.openStream();
        parseMovie(in);
    }
    catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


protected void parseMovie(InputStream json) throws IOException,
JSONException {
    // TODO Auto-generated method stub

    BufferedReader reader = new BufferedReader(new InputStreamReader(json));
    StringBuilder sb = new StringBuilder();
    String line = reader.readLine();
    while (line != null) {
        sb.append(line);
        line = reader.readLine();
    }
    reader.close();
    System.out.println(sb);
    JSONObject jobj = new JSONObject(sb.toString());
    System.out.println("jsonobj:" + jobj);

    JSONArray array = jobj.getJSONArray("root");

    System.out
        .println("jsonobject   :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
                + array);
}

I get the above JSON data, but I need the S_we value and Sc_wesam data.

How do I do 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-11T21:08:14+00:00Added an answer on June 11, 2026 at 9:08 pm

    You can iterate over individual elements using your JSONArray, and make some assumptions about your data:

    JSONArray array = jobj.getJSONArray("root");
    JSONObject subObj;
    JSONArray subArray;
    
    for (int i = 0; i < array.length(); i++)
    {
        subObj = array.getJSONObject(i);
    
        if (subObj.has("Sc_wesam")) // handle Se_wesam
        {
            subArray = subObj.getJSONArray("Sc_wesam");
    
            for (int j = 0; j < subArray.length(); j++)
            {
                subObj = subArray.getJSONObject(j);
                if (subObj.has("head"))
                    System.out.println("Sc_wesam head value: " +
                                       subObj.getString("head"));
                else if (subObj.has("color"))
                    System.out.println("Sc_wesam color value: " +
                                       subObj.getString("color"));
            }
        }
        else if (subObj.has("Sc_we")) // handle Se_we
        {
            subArray = subObj.getJSONArray("Sc_wesam");
    
            // ... etc.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried several solutions and the result of parsing JSON with GSON always
I have an array left over after parsing JSON that looks like ( -122.1407313,
I have 3 json arrays, each with information listed in the same format: Array:
I am downloading and parsing JSON objects to build a news feed to populate
I have the following code: try { < ... some JSON parsing code ..
I have tried to use the JSON in the android but it seems to
I have recently started parsing JSON documents using SBJSON Parser, and I am able
I have a controller method that has long been handling JSON requests by parsing
Sorry for asking silly question.. I have an array with class objects like: Class
I can't seem to access my objects. after parsing the server string: var json

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.