我在爲大學分配工作中使用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'循環。 –