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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:39:38+00:00 2026-06-17T11:39:38+00:00

I’m using wunderground to get weather information on my java web application. After some

  • 0

I’m using wunderground to get weather information on my java web application.
After some search I came across Gson which seems like a good json parser.

But following some examples I can’t seem to figure out how to skip root elements.
Here is an example of a forecast json request:

{
    "forecast" : {
        "simpleforecast" : {
            "forecastday" : [ {
                "avehumidity" : 61,
                "avewind" : {
                    "degrees" : 342,
                    "dir" : "NNW",
                    "kph" : 11,
                    "mph" : 7
                },
                "conditions" : "Clear",
                "date" : {
                    "ampm" : "PM",
                    "day" : 17,
                    "epoch" : "1358478000",
                    "hour" : 21,
                    "isdst" : "0",
                    "min" : "00",
                    "month" : 1,
                    "monthname" : "January",
                    "pretty" : "9:00 PM CST on January 17, 2013",
                    "sec" : 0,
                    "tz_long" : "America/Chicago",
                    "tz_short" : "CST",
                    "weekday" : "Thursday",
                    "weekday_short" : "Thu",
                    "yday" : 16,
                    "year" : 2013
                },
                "high" : {
                    "celsius" : "11",
                    "fahrenheit" : "52"
                },
                "icon" : "clear",
                "icon_url" : "http://icons-ak.wxug.com/i/c/k/clear.gif",
                "low" : {
                    "celsius" : "-2",
                    "fahrenheit" : "28"
                },
                "maxhumidity" : 76,
                "maxwind" : {
                    "degrees" : 340,
                    "dir" : "NNW",
                    "kph" : 18,
                    "mph" : 11
                },
                "minhumidity" : 38,
                "period" : 1,
                "pop" : 10,
                "qpf_allday" : {
                    "in" : 0.0,
                    "mm" : 0.0
                },
                "qpf_day" : {
                    "in" : 0.0,
                    "mm" : 0.0
                },
                "qpf_night" : {
                    "in" : 0.0,
                    "mm" : 0.0
                },
                "skyicon" : "mostlysunny",
                "snow_allday" : {
                    "cm" : 0,
                    "in" : 0
                },
                "snow_day" : {
                    "cm" : 0,
                    "in" : 0
                },
                "snow_night" : {
                    "cm" : 0,
                    "in" : 0
                }
            },
            {
                "avehumidity" : 59,
                "avewind" : {
                    "degrees" : 172,
                    "dir" : "South",
                    "kph" : 6,
                    "mph" : 4
                },
                "conditions" : "Clear",
                "date" : {
                    "ampm" : "PM",
                    "day" : 18,
                    "epoch" : "1358564400",
                    "hour" : 21,
                    "isdst" : "0",
                    "min" : "00",
                    "month" : 1,
                    "monthname" : "January",
                    "pretty" : "9:00 PM CST on January 18, 2013",
                    "sec" : 0,
                    "tz_long" : "America/Chicago",
                    "tz_short" : "CST",
                    "weekday" : "Friday",
                    "weekday_short" : "Fri",
                    "yday" : 17,
                    "year" : 2013
                },
                "high" : {
                    "celsius" : "10",
                    "fahrenheit" : "50"
                },
                "icon" : "clear",
                "icon_url" : "http://icons-ak.wxug.com/i/c/k/clear.gif",
                "low" : {
                    "celsius" : "-1",
                    "fahrenheit" : "30"
                },
                "maxhumidity" : 84,
                "maxwind" : {
                    "degrees" : 170,
                    "dir" : "South",
                    "kph" : 10,
                    "mph" : 6
                },
                "minhumidity" : 40,
                "period" : 2,
                "pop" : 0,
                "qpf_allday" : {
                    "in" : 0.0,
                    "mm" : 0.0
                }, ..................

Now the part I’m only interested in is forecastday. So what i did is the following:

package entity.json;

import java.util.List;

public class Data {
    private List<Forecast> forecastday;

    public List<Forecast> getForecastdays() {
        return forecastday;
    }
}

Forecast class:

package entity.json;

public class Forecast {
    private int avehumidity;
    private Avewind avewind;
    private String conditions;
    private DateWeather date;
    private CelciusHigh high;
    private String icon_url;
    private CelciusLow low;
    // + constructor, getters, setters

Here is my method:

public void createWeatherForecast(){
        String text = "";
        try {
            URL url = new URL(jsonUrl);
            System.out.println(jsonUrl);
            Scanner s = new Scanner(url.openStream());
            while(s.hasNextLine()){
                text += s.nextLine();
            }
            Data weather = new Gson().fromJson(text, Data.class);
            System.out.println(new Gson().toJson(weather));
            System.out.println(weather.getForecastdays().get(0).getAvewind());
        } catch (IOException ex) {
            Logger.getLogger(WeatherController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Now should I also be focussing on forecast and simpleforecast?

  • 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-17T11:39:39+00:00Added an answer on June 17, 2026 at 11:39 am

    Just because you’re “only interested” in one part of the JSON object doesn’t make Gson magically be able to provide that 😉

    You either need to make your POJO to match the JSON object, or write a custom deserializer that discards the portion of the JSON object you’re not interested in and returns an instance of your Data class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.