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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:28:01+00:00 2026-05-23T01:28:01+00:00

I have the following JSON: [ { outcome: Success, message: , identity: , delay:

  • 0

I have the following JSON:

    [
  {
    "outcome": "Success",
    "message": "",
    "identity": "",
    "delay": "0",
    "symbol": "AAPL",
    "companyname": "Apple Inc.",
    "date": "Jun 08",
    "time": " 4:52 PM EDT",
    "open": "330.88",
    "close": "332",
    "previousclose": "332.04",
    "high": "334.8",
    "low": "330.51",
    "last": "332",
    "change": "-0.04",
    "percentchange": "-0.012",
    "volume": "1239421",
    "created_at": "1307581193"
  },
  {
    "outcome": "Success",
    "message": "",
    "identity": "",
    "delay": "0",
    "symbol": "GOOG",
    "companyname": "Google Inc.",
    "date": "Jun 08",
    "time": " 3:59 PM EDT",
    "open": "516.76",
    "close": "519.28",
    "previousclose": "519.03",
    "high": "521.14",
    "low": "515.79",
    "last": "519.28",
    "change": "0.25",
    "percentchange": "0.048",
    "volume": "229886",
    "created_at": "1307576900"
  }
]

Here is my Java:

JSONArray jquotes = new JSONArray(json.toString());
                    if (jquotes.length() > 0) {
                        for (int i = 0; i < jquotes.length(); i++) {

                            JSONObject quote = jquotes.getJSONObject(i);

                            Quote myQuote = new Quote();
                            myQuote.setName(quote.getString("companyname"));
                            myQuote.setSymbol(quote.getString("symbol"));
                            myQuote.setLastTradePriceOnly(quote.getString("last"));
                            myQuote.setChange(quote.getString("change"));
                            myQuote.setPercentChange(quote.getString("percentchange"));

                            quotesAdapter.add(myQuote);
                        }
                    }

I am getting the exception:

value of type org.json.JSONArray cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:107)
  • 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-23T01:28:02+00:00Added an answer on May 23, 2026 at 1:28 am

    As the contents of the question currently stand, the provided JSON deserializes without error with the provided code.

    For the working code below, all I did was copy and paste what’s in the question, and it runs as expected.

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.json.JSONArray;
    import org.json.JSONObject;
    
    public class Foo
    {
      public static void main(String[] args) throws Exception
      {
        String jsonInput = readJsonInput(new File("input.json"));
        JSONArray jquotes = new JSONArray(jsonInput);
        int length = jquotes.length();
        List<Quote> quotes = new ArrayList<Quote>(length);
        if (length > 0)
        {
          for (int i = 0; i < length; i++)
          {
            JSONObject quote = jquotes.getJSONObject(i);
    
            Quote myQuote = new Quote();
            myQuote.setName(quote.getString("companyname"));
            myQuote.setSymbol(quote.getString("symbol"));
            myQuote.setLastTradePriceOnly(quote.getString("last"));
            myQuote.setChange(quote.getString("change"));
            myQuote.setPercentChange(quote.getString("percentchange"));
    
            quotes.add(myQuote);
          }
        }
        System.out.println(quotes);
      }
    
      private static String readJsonInput(File inputFile) throws Exception
      {
        StringBuilder result = new StringBuilder();
        BufferedReader reader = new BufferedReader(new FileReader(inputFile));
        for (String line = null; (line = reader.readLine()) != null;)
        {
          result.append(line);
        }
        return result.toString();
      }
    }
    
    class Quote
    {
      private String name;
      private String percentChange;
      private String change;
      private String lastTradePriceOnly;
      private String symbol;
    
      void setName(String name)
      {
        this.name = name;
      }
    
      void setPercentChange(String percentChange)
      {
        this.percentChange = percentChange;
      }
    
      void setChange(String change)
      {
        this.change = change;
      }
    
      void setLastTradePriceOnly(String lastTradePriceOnly)
      {
        this.lastTradePriceOnly = lastTradePriceOnly;
      }
    
      void setSymbol(String symbol)
      {
        this.symbol = symbol;
      }
    
      @Override
      public String toString()
      {
        return String.format(
            "{Quote: name=%s, percentChange=%s, change=%s, lastTradePriceOnly=%s, symbol=%s}",
            name, percentChange, change, lastTradePriceOnly, symbol);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON { CompanyName = Len LTD; Date = 3/31/2011; DimensionsOfLoad
I have the following JSON: { status : success, 0: { link : test1,
I have the following JSON date returned from a MVC page e.g. DateProcessed:\/Date(1258125238090)\/ and
I have the following JSON returned from an AJAX call: {rows:[{Date:07/10/2011,Value:1206,Action:Drink}, {Date:07/11/2011,Value:2288,Action:Pie}, {Date:07/12/2011,Value:1070,Action:Drink}, {Date:07/13/2011,Value:1535,Action:Beer},
I have the following JSON structure: [{ id:10, class: child-of-9 }, { id: 11,
I have the following json code file named: sections.json { section1: { priority: 1,
I have the following JSON object: { response: { status: 200 }, messages: [
I have the following Json : {\doc\:{\info\:{\allowDistribution\:\true\,\allowSearch\:\true\,\calaisRequestID\:\67a02f61-7e45-cfc4-1276-e123c5f7422f\,\externalID\:\\,\id\:\ http://id.opencalais.com/dBo1YRiQeqS-kfO-m9UeWA \,\docId\:\ http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb \,\document\:\What type of music
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have a configuration file in the following JSON format: { key1: value1, key2:

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.