我正在尝试传递一个参数,userID
然后以JSON
.
因此,如果userID=1
那么响应将是
[{"carname":"Honda","carmodel":"Civic"}]
,如果userID=5
那么响应将是
[{"carname":"Honda","carmodel":"Civic"},{"carname":"VW","carmodel":"Golf"},{"carname":"Ford","carmodel":"Focus"}]
但由于某种原因,参数没有被传递,如果是,那么我无法检索值JSON
这是我下面的代码:
public void getComments(int userID){
String passURL = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest
(passURL, new Response.Listener<JSONArray>(){
@Override
public void onResponse(JSONArray jsonArray) {
try {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String carName = jsonObject.getString("carname");
String carModel = jsonObject.getString("carmodel");
UserStore userStore = new UserStore(carName, carModel);
list.add(userStore);
adapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("userID", Integer.toString(userID));
return params;
}
};
requestQueue.add(jsonArrayRequest);
}
我怀疑这与我在传递参数后试图从数组中获取响应这一事实有关。我的php
作品在Postman