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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:02:19+00:00 2026-06-03T21:02:19+00:00

I have a simple issue, unable to tackle it out since 2 days. Being

  • 0

I have a simple issue, unable to tackle it out since 2 days. Being a newbie in Android is what seems grueling at times. But here goes,

A simple JSON file is depicted as below:

"results" : [
{
     "value1" : {
        "sub-value" : {
           "sub-sub-value1" : "This is one value",
           "sub-sub-value2" : "This is one more.."
        }
     },
     "value2" : "http://someURL.com",
     "value3" : "areferencejunkvalue",
  }
],
...<many such result sets>
 "status" : "status_value"
}

The code is as below for parsing this simple JSON file.

try {
JSONArray results = json.getJSONArray("results");
JSONObject value1 = results.getJSONObject("value1");
JSONArray subvalue = locationGeom.getJSONArray("sub-value");

for (int i = 0; i < results.length(); i++) {
      // Gets data for value2,value3
      String value2 = results.getString("value2");
      String value3 = results.getString("value3");

      // Gets data from the sub-sub-value1
      String ssv1 = subvalue.getJSONObject(0).getString("sub-sub-value1").toString();
      // Gets data from the sub-sub-value2
      String ssv2 = subvalue.getJSONObject(0).getString("sub-sub-value2").toString();
    }
 } catch (JSONException e1) {
Log.e("E", "Issue is here..");
e1.printStackTrace();
}

Now the issue is, the following:

05-06 23:39:07.846: W/System.err(378): org.json.JSONException: Value [JSONObject parsed] at results of type org.json.JSONArray cannot be converted to JSONObject

Can anybody tell me where am I going wrong here?
Help is sincerely appreciated.

  • 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-03T21:02:22+00:00Added an answer on June 3, 2026 at 9:02 pm

    sub-value is not an array, but an object, e.g.:

    JSONArray results = json.getJSONArray("results");
    JSONObject value1 = results.getJSONObject(0).getJSONObject("value1");
    JSONObject subvalue = locationGeom.getJSONObject("sub-value");
    

    The basic extraction rules are pretty simple:

    from \ get  |  JSONObject                     | JSONArray
    ------------+---------------------------------+--------------------------------
    JSONObject  | jobj.getJSONObject(String key); | jobj.getJSONArray(String key);
    JSONArray   | jobj.getJSONObject(int index);  | jobj.getJSONArray(int index);
    

    Please also refer to:

    • The official JSON site – json.org
    • JSONObject / JSONArray android documentation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yall: I have a simple question, it might be a simple configuration issue, but
I have what I think should be a fairly simple mapping issue, but not
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have a simple issue -- I would like to check a field to
I have a simple XML extraction issue that should be solvable with straight PHP
I have what should be a simple issue: On my newest rendition of http://www.derekbeck.com/1775
I am having an issue with somethign that I thoguth woudl have been simple.
I have made a simple test application for the issue, two winforms each containing
I am have an issue with the page reloading. I have written a simple
Strange issue I am having with my MVC3 project. I have followed a simple

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.