Java Android-如何从API(RotterToMatoES)JSON获取url/链接
这是我代码的一部分,在我的代码中,我得到了一部电影的“标题”和“概要”,但“个人资料”部分由于某种原因不起作用,我无法从网站上获得img链接,以下是,谢谢你的帮助Java Android-如何从API(RotterToMatoES)JSON获取url/链接,java,android,json,api,networking,Java,Android,Json,Api,Networking,这是我代码的一部分,在我的代码中,我得到了一部电影的“标题”和“概要”,但“个人资料”部分由于某种原因不起作用,我无法从网站上获得img链接,以下是,谢谢你的帮助 @Override protected void onPostExecute(String response) { super.onPostExecute(response); try { // convert the
@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**
}
@覆盖
受保护的void onPostExecute(字符串响应){
super.onPostExecute(响应);
试一试{
//将字符串响应转换为JSON对象
JSONObject jsonResponse=新的JSONObject(响应);
//获取响应中的电影数组
JSONArray jArray=jsonResponse.getJSONArray(“电影”);
//将每部电影的标题添加到列表中
movieTitles=新的ArrayList();
movieSynopsis=newarraylist();
movieImgUrl=新建ArrayList();//**有问题**
for(int i=0;i
将代码修改为
movieImgUrl.add(movie.getJSONObject("posters").getString("profile"));
这是因为posters
是一个JSONObject
并且图像链接在该JSONObject内部