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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:13:54+00:00 2026-06-11T20:13:54+00:00

While fetching json data I am getting error: JSONArray cannot be converted to JSONObject

  • 0

While fetching json data I am getting error:

JSONArray cannot be converted to JSONObject

Code for json generate:

JSONObject parent = new JSONObject();
DatabaseHandler dbh = new DatabaseHandler(getApplicationContext());  
            for(int i=0; i < allEds.size(); i++){
                String edsText = allEds.get(i).getText().toString();                                           
               //spinner = allSpns.get(i);
               String spinSelected=allSpns.get(i).getSelectedItem().toString();                  
               try
                {
                   JSONObject json = new JSONObject();          
                   json.put("Id", i);
                   json.put("FieldName", edsText);
                   json.put("FieldType",spinSelected);
                   parent.accumulate("data", json);



                }
                catch (JSONException e)
                {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }                   

            }
Generated json is   
            {"data":
[{"FieldType":"Account Number","FieldName":"r","Id":0},
  {"FieldType":"Net      Banking Id","FieldName":"tt","Id":1}
 ]}
code for json read
------------------
JSONObject jsonObj = new JSONObject(folderStructure);
        JSONObject data = jsonObj.getJSONObject("data"); 
        String id = data.getString("Id"); 
        String value = data.getString("FieldName"); 
        Log.d("Item name: ", value);    

While reading the above json am getting errors
Any thing wrong with the code??

  • 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-11T20:13:55+00:00Added an answer on June 11, 2026 at 8:13 pm

    Change

    JSONObject data = jsonObj.getJSONObject("data"); 
    

    to

    JSONArray data = jsonObj.getJSONArray("data");
    

    As value of data is JsonArray not JSONObject.

    And to Get individual Ids and Field Names, you should loop through this JSONArray, as follows:

    for(int i=0; i<data.length(); i++)
    {
         JSONObject obj=data.getJSONObject(i);
         String id = obj.getString("Id"); 
            String value = obj.getString("FieldName"); 
            Log.d("Item name: ", value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a problem while fetching data. Its giving CFHTTPMessageGetResponseStatusCode(response) as 302 .
i am having problems while fetching data from kml file. geoXml.parse(http://localhost/maps/phpmysqlajax_genkml.kml); error in console
I am not getting response while fetching result from my code using AJAX. while
I got the below error while fetching some data from sever. While fetching data,
I am getting org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 error while fetching
While fetching Boolean data from database with hibernate SQL query gives the following error
I have a simple function that shows loading spinner while fetching data (usually takes
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
I am using Prestashop. I am getting trouble while fetching all images for a
Possible Duplicate: Sending and Parsing JSON in Android I am fetching JSON Data from

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.