Ok, so here what i did to fixed my problem:
PHP
....//Some query from mysql table
$posts = array(); //Added
foreach($data as $row) {
$posts[] = array('post'=>$row); //New
}echo json_encode(array('posts'=>$posts)); //then print here
ANDROID JAVA
JSONObject json = new JSONObject(response);
JSONArray jArray = json.getJSONArray("posts");
for (int i = 0; i < jArray.length(); i++) {
JSONObject e = jArray.getJSONObject(i);
String s = e.getString("post");
JSONObject jObject = new JSONObject(s);
String iid = jObject.getString("id"); //Put the id here or you can add more if you have more than 1 column
Log.w("THE REQUESTED ID ARE",iid);
.... //Use the requested id here
}
Thanks for this link:
Send and Receive JSON between Android and PHP Web Service
Thanks.
solved Android Studio – org.json.JSONObject cannot be converted to JSONArray