Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to parse this json in android
    primarykey
    data
    text
    <p>I need to parse this json and get the itemvotecounts, and firstrankvotescounts. </p> <pre><code>[ [ { "itm_id": "22", "itm_nam": "movie1", "user_id": "8", "overall": [ { "itm_id": "23", "itm_nam": "movie2", "firstrankvotecounts": "27", "overallrank": 1, "overalltotalitems": 16, "overallmaxrank": "16" } ], "itemoverallrank": "2", "itemvotecounts": "23", "particularcategory": [ { "itm_id": "23", "itm_nam": "movie2", "firstrankvotecounts": "27", "particularcategoryrank": 1, "particularcategorytotalitems": 12, "categorymaxrank": "12" } ], "itemparticularcategoryrank": "2" } ], [ { "itm_id": "42", "itm_nam": "How to train your dragon", "user_id": "8", "overall": [ { "itm_id": "23", "itm_nam": "movie2", "firstrankvotecounts": "27", "overallrank": 1, "overalltotalitems": 16, "overallmaxrank": "16" } ], "itemoverallrank": "9", "itemvotecounts": "5", "particularcategory": [ { "itm_id": "23", "itm_nam": "movie2", "firstrankvotecounts": "27", "particularcategoryrank": 1, "particularcategorytotalitems": 12, "categorymaxrank": "12" } ], "itemparticularcategoryrank": "8" } ] ] </code></pre> <p>I used the following code.</p> <pre><code>try { JSONArray jsonArray = new JSONArray("the json"); Log.v("Number of entries ",Integer.toString(jsonArray.length())); for (int i = 1; i &lt; jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); String itm_vote = jsonObject.getString("itemvotecounts"); Log.v("item vote count ",itm_vote); }} catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } </code></pre> <p>and get the following error.</p> <pre><code>03-22 23:05:01.067: W/System.err(389): org.json.JSONException: JSONArray[1] is not a JSONObject. 03-22 23:05:01.077: W/System.err(389): at org.json.JSONArray.getJSONObject(JSONArray.java:268) 03-22 23:05:01.077: W/System.err(389): at com.http.post.HttpPostCheckActivity$responseCheck.doInBackground(HttpPostCheckActivity.java:90) 03-22 23:05:01.077: W/System.err(389): at com.http.post.HttpPostCheckActivity$responseCheck.doInBackground(HttpPostCheckActivity.java:1) 03-22 23:05:01.087: W/System.err(389): at android.os.AsyncTask$2.call(AsyncTask.java:185) 03-22 23:05:01.087: W/System.err(389): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256) 03-22 23:05:01.087: W/System.err(389): at java.util.concurrent.FutureTask.run(FutureTask.java:122) 03-22 23:05:01.097: W/System.err(389): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648) 03-22 23:05:01.097: W/System.err(389): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673) 03-22 23:05:01.097: W/System.err(389): at java.lang.Thread.run(Thread.java:1060) </code></pre>
    singulars
    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