0
我正在請求一個json url並從那裏獲取信息。基於這些信息,我正在對html解析的url進行另一個抽象請求。我需要返回一個包含所有數據的數組列表,但我無法在第二個抽象請求中添加數據。這裏是我的代碼訪問變量出Volley onResponse Android
public ArrayList<List> parseJSONMovies(JSONObject data,View v) throws JSONException {
JSONObject firstArray;
JSONArray internalData;
listMDat= new ArrayList<>();//New Array List
firstArray=data.getJSONObject("data");
JSONObject currOb;
internalData=firstArray.getJSONArray("names");
currOb=internalData.getJSONObject(0);
JSONArray films;
JSONObject cuurFilm;
JSONObject film;
films=currOb.getJSONArray("filmographies");
film=films.getJSONObject(0);
JSONArray allFilms;
allFilms=film.getJSONArray("filmography");
for (int i=0;i<allFilms.length();i++)
{
cuurFilm=allFilms.getJSONObject(i);
getMData=new CLassObject();//Object of the class
getMData.movie_id=cuurFilm.getString("imdbid");
getMData.movie_syn=cuurFilm.getString("title");
//Parse Html by generating the imdb url get the image synopsis and stuff and populate the AlooM Class
String urlIMD="http://www.imdb.com/title/"+getMData.getMovie_id()+"/";
RequestQueue requestS = VS.getRequestQueue();
StringRequest newR = new StringRequest(Request.Method.GET, urlIMD, new Response.Listener<String>() {
public void onResponse(String response) {
// Display the first 500 characters of the response string.
Document doc = Jsoup.parse(response);
Elements image_url = doc.select("link[rel=image_src]");
Elements movie_syn=doc.select("meta[property=og:description]");
Elements movie_title=doc.select("[property=og:title]");
/*I need to add these variables to the classObject*/
String s1=image_url.attr("href");
String s2=movie_syn.attr("content");
String s3=movie_title.attr("content");
getMData.movie_title=s3;
getMData.movie_url=s2;
getMData,movie_syn=s1;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Machar Jhol !!! " + error.getMessage(), Toast.LENGTH_LONG).show();
}
});
requestS.add(newR);
Toast.makeText(getActivity(),"Step2",Toast.LENGTH_LONG).show();
}
Toast.makeText(getActivity(),"Step3",Toast.LENGTH_LONG).show();
return listMDat;
}
}