Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>instead of giving inputstream directly to the GSON constructor, download the JSON string first from the URL and then pass it to the constructor for parsing as below:</p> <pre><code>String source = read(url); Feed feeds=new Gson().fromJson(source ,Feed.class); ArrayList&lt;FeedResult&gt;feed=new ArrayList&lt;FeedResult&gt;(); feed=feeds.getFeed(); for(FeedResult feedResult:feedResults) System.out.println(feedResult); </code></pre> <p>the read function:</p> <pre><code>public static String read(String url){ System.out.println("Connecting to service URL : "+url); InputStream is = null; String result = ""; // http post try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { e.printStackTrace(); } // convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } </code></pre> <p>add toString() function in your FeedResult class, so that it will get printed to console in readable manner:</p> <pre><code>/* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "FeedResult [id=" + id + ", created_time=" + created_time + ", message=" + message + ", thumbnail=" + thumbnail + ", comment_count=" + comment_count + "]"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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