我正在使用RecyclerView
来显示从DB获取的数据。它没有用。
获得错误E / Volley:[33049] BasicNetwork.performRequest:意外的响应代码404.
需要在下面解析响应: -
[ { "code":"23232", "desc":"ddddjdkdkcn", "price":[ "price" ] }, { "code":"de33fd", "desc":"ddds", "price":[ "price" ] } ]
public class Background {
String url = "http://192.168.0.103/android_fetch.php";
Context context;
ArrayList<Data> arrayList = new ArrayList<>();
public Background(Context context) {
this.context = context;
}
public ArrayList<Data> getList() {
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, (String) null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
int count = 0;
while (count < response.length()) {
try {
JSONObject jsonObject = response.getJSONObject(count);
Data data = new Data(jsonObject.getString("code"), jsonObject.getString("desc"), jsonObject.getString("price"));
arrayList.add(data);
count++;
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
});
MySingleton.getInstance(context).addToRequestque(jsonArrayRequest);
return arrayList;
}
}