Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON parsing empty display
    primarykey
    data
    text
    <p>How should I parse that JSON <a href="http://rutube.ru/api/video/editors/?page=1&amp;format=json" rel="nofollow">http://rutube.ru/api/video/editors/?page=1&amp;format=json</a>? I've got empty display. I take example from <a href="http://www.androidhive.info/2012/01/android-json-parsing-tutorial/" rel="nofollow">http://www.androidhive.info/2012/01/android-json-parsing-tutorial/</a></p> <p>JSONPARSER.java</p> <pre><code>public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } public JSONObject getJSONFromUrl(String url) { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); int httpStatus = httpResponse.getStatusLine().getStatusCode(); if (httpStatus != HttpStatus.SC_OK) { 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(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } } HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return jObj; } } </code></pre> <p>MAINACTIVITY.java</p> <pre><code> public class MainActivity extends ListActivity { private static String URL_VIDEO = "http"; private static final String TAG_RESULTS = "results"; private static final String VIDEO_OBJECT = "video"; private static final String VIDEO_ID = "id"; private static final String VIDEO_TITLE = "title"; private static final String VIDEO_CREATED_TS = "created_ts"; JSONArray results = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayList&lt;HashMap&lt;String, String&gt;&gt; resultList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(URL_VIDEO); try { results = json.getJSONArray(TAG_RESULTS); for (int i = 0; i &lt; results.length(); i++) { JSONObject c = results.getJSONObject(i); JSONObject video = c.getJSONObject(VIDEO_OBJECT); String id = video.getString(VIDEO_ID); String title = video.getString(VIDEO_TITLE); String created_ts = video.getString(VIDEO_CREATED_TS); HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put(VIDEO_ID, id); map.put(VIDEO_TITLE, title); map.put(VIDEO_CREATED_TS, created_ts); resultList.add(map); } } catch(JSONException e) { e.printStackTrace(); } ListAdapter adapter = new SimpleAdapter(this, resultList, R.layout.list_video_item, new String[] { VIDEO_OBJECT, VIDEO_TITLE, VIDEO_CREATED_TS }, new int[] { R.id.object, R.id.title, R.id.created_ts }); setListAdapter(adapter); ListView lv = getListView(); } } </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.
 

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