Note that there are some explanatory texts on larger screens.

plurals
  1. POError when getting data from JSON Nested loop in Android
    text
    copied!<p>I tried this but getting error in for loop optJSONObject(i)</p> <pre><code>{ "response": { "code": 1, "message": "success" }, "data": { "updates": [ { "id":"67", "date":"6 months ago", "update_type": "7", "update_id": "67", "name":"ravi" }, { "id":"68", "date":"3 months ago", "update_type": "5", "update_id": "68", "name":"paresh" }, { "id":"69", "date":"1 months ago", "update_type": "6", "update_id": "69", "name":"sampath" }, { "id":"62", "date":"9 months ago", "update_type": "6", "update_id": "62", "name":"raju" } ] } } </code></pre> <p>The code i tried for this is :</p> <pre><code>try { InputStream is = null; is = getApplicationContext().getResources().openRawResource(R.raw.myfile); //CONVERTS STREAM OBJ IN STRING OBJ mJSONString = convertStreamToString(is); JSONObject obj = new JSONObject(mJSONString); JSONObject dataobj = obj.getJSONObject("data"); JSONObject updateobj = dataobj.getJSONObject("update"); //System.out.println(new JSONObject(update)toString(2)); for(int i=0; i&lt;updateobj.length(); i++){ JSONObject object = updateobj.optJSONObject(i); mUpdates = new Mobile_UpdateActivity(); mUpdates.update_id = object.getString("update_id"); mUpdates.site_id = object.getString("site_id"); mUpdates.update_type = object.getString("update_type"); System.out.println(mUpdates.update_id); System.out.println(mUpdates.site_id); System.out.println(mUpdates.update_type); } </code></pre> <p>}</p> <p>But I'm facing an error at **optJSONObject(i)</p> <blockquote> <p>Error: The method optJSONObject(String) in the type JSONObject is not applicable for the arguments (int)**</p> </blockquote>
 

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