这是我尝试过的:数据库在我的本地主机中,我使用的是我自己的 IP。
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONArray array = new JSONArray(response);
for (int x = 0; x<array.length();x++){
JSONObject ob = array.getJSONObject(x);
Alumnos list = new Alumnos();
list.setUsername(ob.getString("username"));
list.setJob(ob.getString("job"));
list.setAge(ob.getInt("age"));
alumnos.add(list);
}
updateRecycler(alumnos);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Error: ", error.toString());
}
}
);
queue.add(stringRequest);
}
我尝试在 Recycler 视图中显示我的结果,但出现下一个错误:
10-03 21:41:28.033 10077-10077/? W/System.err: org.json.JSONException: Value {"result":[{"userid":"1","username":"Luis","job":"developer","age":"23"},{"userid":"2","username":"Alejandro","job":"agronomo","age":"24"},{"userid":"3","username":"Gabriel","job":"Redes","age":"24"}]} of type org.json.JSONObject cannot be converted to JSONArray
我想我可能会遗漏一些非常明显的东西,因为我在 Logcat 中得到了数组。
相关分类