我写了一个PHP脚本,我确信它工作正常,因为它向我展示了下面给出的以下JSON输出.....
JSON结果
{"categories":[{"id":"1","name":"Sub Category 1"},{"id":"3","name":"Sub Category 2"}]}
但问题是当我从微调器中选择主要护理时,子类别没有显示。
JAVA代码:
public void getSubCategory(int cat_id) {
String tag_json_arry = "json_object_req";
JsonObjectRequest req = new JsonObjectRequest(AppConstants.getSubCategories(cat_id),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
List<String> responseList = new ArrayList<String>();
responseList.add("Choose Brand");
JSONArray jsonArray = response.getJSONArray("categories");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = new JSONObject();
jsonObject = jsonArray.getJSONObject(i);
responseList.add(jsonObject.getString("name"));
Model.Categories model = new Model.Categories();
model.setId(jsonObject.getString("id"));
model.setName(jsonObject.getString("name"));
sub_categories.add(model);
}
refreshSubCategorySpinner(responseList);
Log.e("Msg", response.toString());
Toast.makeText(getApplicationContext(), "Sucess", Toast.LENGTH_LONG).show();
} catch (Exception exp) {
exp.printStackTrace();
Toast.makeText(getApplicationContext(), "" + exp.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show();
Log.e("ZoyaMsg", error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(req, tag_json_arry);
}