JSON URL from StackExchange API returning jibberish? — oracle-tech

    Forum Stats

  • 3,702,040 Users
  • 2,239,552 Discussions
  • 7,835,730 Comments

Discussions

JSON URL from StackExchange API returning jibberish?

I have a feeling I'm doing something wrong here, but I'm not quite sure if I'm missing a step, or am just having an encoding problem or something. Here's my code:

<span class="pln" style="background: transparent;">URL url </span><span class="pun" style="background: transparent;">=</span><span class="pln" style="background: transparent;"> </span><span class="kwd" style="color: #00008b; background: transparent;">new</span><span class="pln" style="background: transparent;"> URL</span><span class="pun" style="background: transparent;">(</span><span class="str" style="color: #800000; background: transparent;"><span>"</span><a class="jive-link-external-small" href="http://api.stackoverflow.com/0.8/questions/2886661" rel="nofollow">http://api.stackoverflow.com/0.8/questions/2886661</a><span>"</span></span><span class="pun" style="background: transparent;">);</span><span class="pln" style="background: transparent;">  </span><span class="typ" style="color: #2b91af; background: transparent;">BufferedReader</span><span class="pln" style="background: transparent;"> in </span><span class="pun" style="background: transparent;">=</span><span class="pln" style="background: transparent;"> </span><span class="kwd" style="color: #00008b; background: transparent;">new</span><span class="pln" style="background: transparent;"> </span><span class="typ" style="color: #2b91af; background: transparent;">BufferedReader</span><span class="pun" style="background: transparent;">(</span><span class="kwd" style="color: #00008b; background: transparent;">new</span><span class="pln" style="background: transparent;"> </span><span class="typ" style="color: #2b91af; background: transparent;">InputStreamReader</span><span class="pun" style="background: transparent;">(</span><span class="pln" style="background: transparent;">url</span><span class="pun" style="background: transparent;">.</span><span class="pln" style="background: transparent;">openStream</span><span class="pun" style="background: transparent;">()));</span><span class="pln" style="background: transparent;"> </span><span class="com" style="color: #808080; background: transparent;">// Question q = new Gson().fromJson(in, Question.class);</span><span class="pln" style="background: transparent;"> </span><span class="typ" style="color: #2b91af; background: transparent;">String</span><span class="pln" style="background: transparent;"> line</span><span class="pun" style="background: transparent;">;</span><span class="pln" style="background: transparent;"> </span><span class="typ" style="color: #2b91af; background: transparent;">StringBuffer</span><span class="pln" style="background: transparent;"> content </span><span class="pun" style="background: transparent;">=</span><span class="pln" style="background: transparent;"> </span><span class="kwd" style="color: #00008b; background: transparent;">new</span><span class="pln" style="background: transparent;"> </span><span class="typ" style="color: #2b91af; background: transparent;">StringBuffer</span><span class="pun" style="background: transparent;">();</span><span class="pln" style="background: transparent;"> </span><span class="kwd" style="color: #00008b; background: transparent;">while</span><span class="pln" style="background: transparent;"> </span><span class="pun" style="background: transparent;">((</span><span class="pln" style="background: transparent;">line </span><span class="pun" style="background: transparent;">=</span><span class="pln" style="background: transparent;"> in</span><span class="pun" style="background: transparent;">.</span><span class="pln" style="background: transparent;">readLine</span><span class="pun" style="background: transparent;">())</span><span class="pln" style="background: transparent;"> </span><span class="pun" style="background: transparent;">!=</span><span class="pln" style="background: transparent;"> </span><span class="kwd" style="color: #00008b; background: transparent;">null</span><span class="pun" style="background: transparent;">)</span><span class="pln" style="background: transparent;"> </span><span class="pun" style="background: transparent;">{</span><span class="pln" style="background: transparent;"> content</span><span class="pun" style="background: transparent;">.</span><span class="pln" style="background: transparent;">append</span><span class="pun" style="background: transparent;">(</span><span class="pln" style="background: transparent;">line</span><span class="pun" style="background: transparent;">);</span><span class="pln" style="background: transparent;"> </span><span class="pun" style="background: transparent;">}</span>

When I print content, I get a whole bunch of wingdings and special characters, basically jibberish. I would copy and past it here, but that isn't working. What am I doing wrong?

This discussion has been closed.