Android - 如何从API(rottentomatoes)JSON获取URL /链接

时间:2013-01-10 12:15:30

标签: java android json api networking

这是我的代码的一部分,在我的代码中我得到了电影的“标题”和“概要”,但“个人资料”部分由于某种原因不起作用,我无法获得img从网站链接,这是website api,谢谢你的帮助。

@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 个答案:

答案 0 :(得分:1)

将代码修改为

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

这是因为postersJSONObject,图像链接在JSONObject内部。