Example usage for twitter4j JSONTokener JSONTokener

List of usage examples for twitter4j JSONTokener JSONTokener

Introduction

In this page you can find the example usage for twitter4j JSONTokener JSONTokener.

Prototype

public JSONTokener(InputStream is) 

Source Link

Usage

From source file:edu.smc.mediacommons.modules.WeatherModule.java

License:Open Source License

public WeatherModule(String search) {
    InputStream is = null;//w  w  w  .j  a v a 2 s.c o  m
    JSONObject result = null;

    String baseUrl = "http://query.yahooapis.com/v1/public/yql?q=";
    String query = "select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\""
            + search + "\")";

    try {
        String fullUrlStr = baseUrl + URLEncoder.encode(query, "UTF-8") + "&format=json";
        URL fullUrl = new URL(fullUrlStr);
        is = fullUrl.openStream();

        JSONTokener tok = new JSONTokener(is);
        result = new JSONObject(tok);
    } catch (JSONException | IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    response = result;
}