2013-01-10 51 views
0

这是我的代码的一部分,在我的代码中,我获得了电影的“标题”和“大纲”,但“profile “部分由于某种原因不起作用,我无法从网站获得img链接,这里是website api,谢谢你的帮助。Android - 如何从API获取url /链接(rottentomatoes)JSON

@Override 


    protected void onPostExecute(String response) { 
       super.onPostExecute(response); 

       try { 
        // convert the String response to a JSON object 
        JSONObject jsonResponse = new JSONObject(response); 

        // fetch the array of movies in the response 
        JSONArray jArray = jsonResponse.getJSONArray("movies"); 

        // add each movie's title to a list 
        movieTitles = new ArrayList<String>(); 
        movieSynopsis = new ArrayList<String>(); 

        movieImgUrl= new ArrayList<String>(); // **problematic** 

        for (int i = 0; i < jArray.length(); i++) { 
         JSONObject movie = jArray.getJSONObject(i);     

          movieTitles.add(movie.getString("title")); 

          movieSynopsis.add(movie.getString("synopsis")); 

          movieImgUrl.add(movie.getString("profile")); // **problematic** 


        } 

回答

1

修改代码为

movieImgUrl.add(movie.getJSONObject("posters").getString("profile")); 

这是因为postersJSONObject和图像链接是的JSONObject内。

+0

谢谢! – user1924895