,让我的记录列表通过SQL的PHP返回我的以下内容:Android的凌空JsonArrayRequest
$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"}
)
现在,作为一个过程,在Android与排球,我有以下的,但显然不工作:
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());
}
错误:
com.android.volley.ParseError: org.json.JSONException: Value Array of Type java.lang.String cannot be converted to JSONArray
我的只剩下机智修改凌空欣尝试,并抛出了同样的错误
try {
Integer cantidad = jsonArray.length();
Log.e("cantidad: ", cantidad.toString());
}
我尝试这一点,并继续同样的错误
public void onResponse(JSONArray response) {
for(int i = 0; i < response.length(); i++) {
try {
Log.i("SUCCESS", response.toString());
}
.....
什么是你的questi上? –