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

  • Home
  • SEARCH
  • 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 9048107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:04:27+00:00 2026-06-16T12:04:27+00:00

I am having trouble parsing JSON when there is multiple arrays. This is an

  • 0

I am having trouble parsing JSON when there is multiple arrays. This is an example of the JSON:

{
   "topics":[
      {
         "posts":[
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Topic #1",
               "contents":"Hello!"
            },
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Reply #1",
               "contents":"Hello!"
            },
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Reply #2",
               "contents":"Hello!"
            }
         ]
      },
      {
         "posts":[
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Topic #2",
               "contents":"Hello!"
            },
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Reply #1",
               "contents":"Hello!"
            },
            {
               "date":"01/01/01 01:01",
               "user":"Example",
               "subject":"Example Reply #2",
               "contents":"Hello!"
            }
         ]
      }
   ]
}

In each of the posts array the first one is the main topic itself and then the rest are replies, the amount of replies is varied and this is just an example.

What I am looking to do is take the user, subject and contents from the main post, the replies I want to ignore.

What I have tried so far after looking at some tutorials is:

try {
    JSONArray threads = jo.getJSONArray(THREADS_TAG); // jo is a JSONObject parameter.

    for (int i = 0; i < threads.length(); i++) {
        JSONObject c = threads.getJSONObject(i);
        JSONObject post = c.getJSONObject(POSTS_TAG);

        Log.i(TAG, "Name: " + post.getString(NAME_TAG));
    }
    } catch (JSONException e) {
        Log.e(TAG, "Exception:");
        e.printStackTrace();
}

But I am having problems with this and I am getting an exception:

at posts of type org.json.JSONArray cannot be converted to JSONObject

  • 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-16T12:04:29+00:00Added an answer on June 16, 2026 at 12:04 pm

    You can do something like this

    try {
        JSONArray threads = jo.getJSONArray("topics");
    
        for (int i = 0; i < threads.length(); i++) {
            JSONArray posts = threads.getJSONObject(0).getJSONArray("posts");
            user[i]=posts.getJSONObject(0).getString("user");
            subject[i]=posts.getJSONObject(0).getString("subject");
            contents[i]=posts.getJSONObject(0).getString("contents");
        }
        } catch (JSONException e) {
            Log.e(TAG, "Exception:");
            e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble parsing an iso date from my json api/mongodb using rest kit.
I'm having trouble parsing Json string to Objects in C#. I'm using this: JavaScriptSerilizer
I am having trouble parsing my JSON which i get from javascript. The format
I'm having some trouble parsing a JSON that I obtain from my DB to
I'm having trouble parsing a json to a model. Here is the JSON: [
I'm having trouble parsing a Twitter search result with the built in iOS JSON
I am playing around with parsing JSON in jQuery and I am having trouble.
I'm working with FlexJSON and am having trouble parsing a Date object from an
I'm having trouble in parsing my JSON data in jQuery autocomplete. My JSON comes
I've having trouble with parsing user input with Javascript, where I can't get the

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.