我在为大学分配工作中使用TheMovieDB API,并且我很难理解如何从嵌套的JSON文件格式访问值。如何从嵌套的JSON文件中检索数据
目前,我的代码如下所示:
httpConnect jParser = new httpConnect();
String json = jParser.getJSONFromUrl(url);
jsonData = json.toString();
JSONObject json1obj = new JSONObject(json);
JSONArray json1arr = json1obj.getJSONArray("results");
String jsonResults = json1arr.toString();
JSONObject first = new JSONArray(jsonResults).getJSONObject(0);
JSONArray second = first.getJSONArray("poster_path");
String secondString = second.toString();
poster_path = secondString.toString();
我能够进入第一层(“结果“)但我遇到麻烦比这更深。总体目标是访问“poster_path”对象。我是Java和JSON的新手,所以这可能看起来像一个愚蠢的问题。任何帮助表示赞赏:)
'json1arr'是一个数组。你需要使用'for'循环。 –