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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:22:10+00:00 2026-06-14T22:22:10+00:00

Why is my JSONArray being returned as a JSONObject? Or maybe I’m mistaken. I’m

  • 0

Why is my JSONArray being returned as a JSONObject? Or maybe I’m mistaken. I’m trying to parse some data from the JSON located here. I read previous SO questions regarding this topic(such as the question asked Here and what I’ve learned is that it’s important to correctly distinguish between a JSONArray and a JSONObject.

It looks to me like it’s both, more specifically it looks like a JSONArray of JSONObjects, each of which contains name:value pairs. I’m trying to “dig a little deeper to get my data” like the answer suggested, but I’m getting a JSONException at line 96, which is this one. I thought maybe “data” is not the correct name of the array, but the JSON is printed in the LogCat only when I use that string. Any help would be greatly appreciated guys.

Line 96
weatherData = json.getJSONArray(“data”);

I’ve pasted the relevant code below.

public String getWeatherData() {

    String url = "http://free.worldweatheronline.com/feed/weather.ashx?q="
            + zipCode
            + "&format=json&num_of_days=5&key=e8570995";

    // Create a JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON String from URL
    JSONObject json = jParser.getJSONFromUrl(url);
    // Log.e("WeatherProvider", "Got JSON from URL");
    /*
     * try { currentCond = json.getString("data"); } catch (JSONException
     * e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
     */

    try {
        // Get array of weather data
        weatherData = json.getJSONArray("data");

        Log.e("WeatherProvider", "JSONArray is not null");

        if (weatherData != null) {
            // loop through the data array
            for (int i = 0; i < weatherData.length(); i++) {
                JSONArray innerJSONArray = weatherData.getJSONArray(i);
                JSONObject object = innerJSONArray.getJSONObject(i);

                // Store each json item in a variable
                currentCond = object.getString("value");

                Log.e("WeatherProvider", "current conditin is "
                        + currentCond);
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return currentCond;
}

}

LOGCAT:

11-25 12:03:33.439: W/System.err(4502): org.json.JSONException: Value {"weather":        [{"windspeedMiles":"19","winddirection":"W","date":"2012-11-25","precipMM":"0.0","winddirDe    gree":"280","winddir16Point":"W","weatherIconUrl":[{"value":"http:\/  \/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"}],"tempMinC":"4","windspeedKmph":"31","tempMaxC":"7","weatherCode":"113","tempMaxF":"44","weatherDesc":[{"value":"Sunny"}],"tempMinF":"39"},{"windspeedMiles":"13","winddirection":"WNW","date":"2012-11-26","precipMM":"0.0","winddirDegree":"290","winddir16Point":"WNW","weatherIconUrl":[{"value":"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"}],"tempMinC":"4","windspeedKmph":"21","tempMaxC":"8","weatherCode":"113","tempMaxF":"46","weatherDesc":[{"value":"Sunny"}],"tempMinF":"40"},{"windspeedMiles":"13","winddirection":"NW","date":"2012-11-27","precipMM":"4.5","winddirDegree":"320","winddir16Point":"NW","weatherIconUrl":[{"value":"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png"}],"tempMinC":"0","windspeedKmph":"21","tempMaxC":"8","weatherCode":"296","tempMaxF":"47","weatherDesc":[{"value":"Light rain"}],"tempMinF":"32"},{"windspeedMiles":"13","winddirection":"WNW","date":"2012-11-28","precipMM":"0.0","winddirDegree":"300","winddir16Point":"WNW","weatherIconUrl":[{"value":"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"}],"tempMinC":"1","windspeedKmph":"21","tempMaxC":"7","weatherCode":"113","tempMaxF":"44","weatherDesc":[{"value":"Sunny"}],"tempMinF":"33"},{"windspeedMiles":"15","winddirection":"WNW","date":"2012-11-29","precipMM":"0.0","winddirDegree":"286","winddir16Point":"WNW","weatherIconUrl":[{"value":"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png"}],"tempMinC":"2","windspeedKmph":"23","tempMaxC":"4","weatherCode":"113","tempMaxF":"40","weatherDesc":[{"value":"Sunny"}],"tempMinF":"35"}],"current_condition":[{"observation_time":"04:33 PM","cloudcover":"75","pressure":"1013","visibility":"16","temp_C":"4","temp_F":"39","windspeedMiles":"19","precipMM":"0.0","winddirDegree":"270","winddir16Point":"W","weatherIconUrl":[{"value":"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png"}],"humidity":"48","windspeedKmph":"30","weatherCode":"116","weatherDesc":[{"value":"Partly Cloudy"}]}],"request":[{"type":"Zipcode","query":"11212"}]} at data of type org.json.JSONObject cannot be converted to JSONArray
11-25 12:03:33.449: W/System.err(4502):     at org.json.JSON.typeMismatch(JSON.java:96)
11-25 12:03:33.449: W/System.err(4502):     at org.json.JSONObject.getJSONArray(JSONObject.java:548)
11-25 12:03:33.449: W/System.err(4502):     at com.brightr.weathermate.providers.WeatherProvider.getWeatherData(WeatherProvider.java:90)
11-25 12:03:33.449: W/System.err(4502):     at com.brightr.weathermate.activities.MainActivity.onClick(MainActivity.java:49)
11-25 12:03:33.449: W/System.err(4502):     at android.view.View.performClick(View.java:2532)
11-25 12:03:33.449: W/System.err(4502):     at android.view.View$PerformClick.run(View.java:9293)
11-25 12:03:33.449: W/System.err(4502):     at android.os.Handler.handleCallback(Handler.java:587)
11-25 12:03:33.449: W/System.err(4502):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-25 12:03:33.449: W/System.err(4502):     at android.os.Looper.loop(Looper.java:150)
11-25 12:03:33.449: W/System.err(4502):     at android.app.ActivityThread.main(ActivityThread.java:4263)
11-25 12:03:33.449: W/System.err(4502):     at java.lang.reflect.Method.invokeNative(Native Method)
11-25 12:03:33.449: W/System.err(4502):     at java.lang.reflect.Method.invoke(Method.java:507)
11-25 12:03:33.449: W/System.err(4502):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-25 12:03:33.449: W/System.err(4502):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-25 12:03:33.449: W/System.err(4502):     at dalvik.system.NativeStart.main(Native Method)
  • 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-14T22:22:11+00:00Added an answer on June 14, 2026 at 10:22 pm

    It isn’t an array, but rather it is a JSON object consisting of an array called weather. This should do the trick:

    weatherData = json.getJSONObject("data").getJSONArray("weather");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to feed in some JSON data to my iPhone app, the
I am trying to add string values in JsonArray and after that create Json
I am trying to populate an adapter with information from my jsonArray. I have
Previously i wrote an app that used reflection to serialize data from json to
Possible Duplicate: Sort JavaScript object by key I am creating JSONArray from JSONObject in
I am trying to create a JSON String in the Android application. JSONArray jArrayFacebookData
I have a data dump in a JSON file that I'm trying to pull
I need to store JSONArray in sqlite here is how I Parse it to
I get JsonArray from web service and parse it with Gson to ArrayList of
I'm experiencing some problem loading a JSONArray on the Android. I've constructed the 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.