The PHP that gives me a list of records through an SQL returns the following
PHP
$result = $con->query($query);
for ($set = array (); $row = $result->fetch_assoc(); $set[] = json_encode($row));
print_r($set);
RESULTADO
Array
(
[0] => {"id":"8783","nombre":"pepe","username":"demo"}
[1] => {"id":"8784","nombre":"garcia","username":"demo"}
)
Now as a process that from Android with Volley, I have the following but obviously it does not work
JsonArrayRequest request = new JsonArrayRequest(URL_2,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray jsonArray) {
for(int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String nombre = jsonObject.getString("name");
Log.e("nombre", nombre);
mEntries.add(jsonObject.toString());
}
catch(JSONException e) {
mEntries.add("Error: " + e.getLocalizedMessage());
}
The error it throws is
com.android.volley.ParseError: org.json.JSONException: Value Array of Type java.lang.String cannot be converted to JSONArray
I thank you if you could verify the Volley or modify the PHP to suit the Volley
I modify the volley leaving only the following inside the try and it throws the same error
try {
Integer cantidad = jsonArray.length();
Log.e("cantidad: ", cantidad.toString());
}