2013-01-10 63 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