Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This <a href="http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html" rel="nofollow">simple code from JavaCodeGeeks</a> will parse a JSON beautifully (see below). As for specifically why your code is not working I do not know.</p> <pre><code>public class JsonParsingActivity extends Activity { String url = "http://search.twitter.com/search.json?q=javacodegeeks"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); InputStream source = retrieveStream(url); Gson gson = new Gson(); Reader reader = new InputStreamReader(source); SearchResponse response = gson.fromJson(reader, SearchResponse.class); Toast.makeText(this, response.query, Toast.LENGTH_SHORT).show(); List&lt;Result&gt; results = response.results; for (Result result : results) { Toast.makeText(this, result.fromUser, Toast.LENGTH_SHORT).show(); } } private InputStream retrieveStream(String url) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); try { HttpResponse getResponse = client.execute(getRequest); final int statusCode = getResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url); return null; } HttpEntity getResponseEntity = getResponse.getEntity(); return getResponseEntity.getContent(); } catch (IOException e) { getRequest.abort(); Log.w(getClass().getSimpleName(), "Error for URL " + url, e); } return null; } } </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.
    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