*我正在按类别ID提取电影,第一个API列表具有所有类别名称和类别ID,第二个API则按类别ID列出所有电影信息。那么如何根据类别ID *
加载电影这是主要的类别API和这些格式
{
"message": "Category List",
"status": "1",
"data": [
{
"sub_category_id": "7",
"Category_name": "RTM Prime Original Series"
},
{
"sub_category_id": "8",
"Category_name": "Drama TV"
},
{
"sub_category_id": "9",
"Category_name": "Comedy TV"
},
{
"sub_category_id": "14",
"Category_name": "Kids and Family TV"
}
]
}
这是用于Json数组获取的代码
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
String tv_shows_api = "xyz.php";
final StringRequest stringRequest=new StringRequest(Request.Method.GET, tv_shows_api, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("ressss",response);
try {
JSONObject jsonObject=new JSONObject(response);
JSONArray jsonArray=jsonObject.getJSONArray("data");
for (int i=0;i<jsonArray.length();i++){
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
sub_category_id =jsonObject1.getString("sub_category_id");
ApiForShowsNameAndImage(sub_category_id);
Category_name =jsonObject1.getString("Category_name");
Log.e("checkkkkk",sub_category_id);
tvshowsList.add(new VerticalTvShowsModel(sub_category_id,Category_name,singleItem));
}
tvShowsAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(stringRequest);
这是按子类别ID的电影信息API
{
"message": "Category List",
"status": "1",
"data": [
{
"tbl_series_id": "9",
"Category_name": "",
"Series_name": "Mirzapur",
"thumbnail_image": "http://rtmprime.com/uploads/series_thums_image/1557486181-mirzapur_thumb.jpeg"
}
]
}
这是用于按子类别ID获取电影信息的代码
private void ApiForShowsNameAndImage(final String sub_category_id) {
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
String tv_showsname_api = "xyz.php";
final StringRequest stringRequest=new StringRequest(Request.Method.POST, tv_showsname_api, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("ressss2",response);
try {
JSONObject jsonObject=new JSONObject(response);
JSONArray jsonArray=jsonObject.getJSONArray("data");
for (int i=0;i<jsonArray.length();i++){
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
tbl_series_id =jsonObject1.getString("tbl_series_id");
Category_name2 =jsonObject1.getString("Category_name");
Series_name =jsonObject1.getString("Series_name");
thumbnail_image =jsonObject1.getString("thumbnail_image");
Log.e("checkkkkk2",tbl_series_id);
singleItem.add(new TvShowsNameImageModel(tbl_series_id,Category_name2,Series_name,thumbnail_image));
}
tvShowsAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("sub_category_id", sub_category_id);
Log.e("BBBBBBBBB", params + "");
return params;
}
};
requestQueue.add(stringRequest);