Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alternatives to GSON exists:</p> <ul> <li><a href="https://stackoverflow.com/questions/443499/json-to-map">Convert Json to Map</a></li> <li><a href="http://code.google.com/p/google-gson/issues/detail?id=45" rel="nofollow noreferrer">http://code.google.com/p/google-gson/issues/detail?id=45</a>.</li> </ul> <p>This snippet may help to do a <strong>generic</strong> decoder:</p> <pre><code>Map&lt; String, Object &gt; decoded = gson.fromJson(data, new TypeToken&lt; Map&lt; String, Object&gt;&gt;() {}.getType()); </code></pre> <p>The following code is a beginning of a <strong>specific</strong> decoder:</p> <pre><code>import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import com.google.gson.Gson; public class Test_Application { public static void main( String[] args ) throws Exception { Gson gson = new Gson(); String json = readUrl( "http://api.wunderground.com/api/57dd9039b81a9c21/" + "conditions/q/CA/San_Francisco.json" ); System.out.println( json ); Map&lt; String, Object &gt; decoded = gson.fromJson( json, new TypeToken&lt; Map&lt; String, Object&gt;&gt;() {}.getType()); System.out.println( decoded ); Answer answer = gson.fromJson( json, Answer.class ); System.out.println( answer.response.version ); System.out.println( answer.response.termsofService ); System.out.println( answer.response.features.get( "conditions" )); System.out.println( answer.current_observation.image ); System.out.println( answer.current_observation.display_location ); } static class Response { String version; URL termsofService; Map&lt; String, String &gt; features; } static class Observation { Map&lt; String, String &gt; image; Map&lt; String, String &gt; display_location; // TODO: complete me } static class Location { // TODO: complete me } static class Answer { Response response; Observation current_observation; Location display_location; // TODO: complete me } </code></pre> <p>At this state of development, it returns:</p> <pre><code>{response={version=0.1, termsofService=http://www.wunderground.com/weather/api/d/terms.html, features={conditions=1.0}}, current_observation={image={url=http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png, title=Weather Underground, link=http://www.wunderground.com}, display_location={full=San Francisco, CA, city=San Francisco, state=CA, state_name=California, country=US, country_iso3166=US, zip=94101, latitude=37.77500916, longitude=-122.41825867, elevation=47.00000000}, observation_location={full=SOMA - Near Van Ness, San Francisco, California, city=SOMA - Near Van Ness, San Francisco, state=California, country=US, country_iso3166=US, latitude=37.773285, longitude=-122.417725, elevation=49 ft}, estimated={}, station_id=KCASANFR58, observation_time=Last Updated on February 19, 8:16 AM PST, observation_time_rfc822=Tue, 19 Feb 2013 08:16:18 -0800, observation_epoch=1361290578, local_time_rfc822=Tue, 19 Feb 2013 08:16:18 -0800, local_epoch=1361290578, local_tz_short=PST, local_tz_long=America/Los_Angeles, local_tz_offset=-0800, weather=Mostly Cloudy, temperature_string=48.7 F (9.3 C), temp_f=48.7, temp_c=9.3, relative_humidity=83%, wind_string=From the ESE at 1.0 MPH, wind_dir=ESE, wind_degrees=109.0, wind_mph=1.0, wind_gust_mph=0.0, wind_kph=1.6, wind_gust_kph=0.0, pressure_mb=1012, pressure_in=29.88, pressure_trend=-, dewpoint_string=44 F (7 C), dewpoint_f=44.0, dewpoint_c=7.0, heat_index_string=NA, heat_index_f=NA, heat_index_c=NA, windchill_string=49 F (9 C), windchill_f=49, windchill_c=9, feelslike_string=49 F (9 C), feelslike_f=49, feelslike_c=9, visibility_mi=10.0, visibility_km=16.1, solarradiation=, UV=0, precip_1hr_string=0.00 in ( 0 mm), precip_1hr_in=0.00, precip_1hr_metric= 0, precip_today_string=0.02 in (1 mm), precip_today_in=0.02, precip_today_metric=1, icon=mostlycloudy, icon_url=http://icons-ak.wxug.com/i/c/k/mostlycloudy.gif, forecast_url=http://www.wunderground.com/US/CA/San_Francisco.html, history_url=http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANFR58, ob_url=http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725}} 0.1 http://www.wunderground.com/weather/api/d/terms.html 1 {url=http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png, title=Weather Underground, link=http://www.wunderground.com} {full=San Francisco, CA, city=San Francisco, state=CA, state_name=California, country=US, country_iso3166=US, zip=94101, latitude=37.77500916, longitude=-122.41825867, elevation=47.00000000} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload