遍历JSON数组以显示在recyclerview中

时间:2019-05-29 20:13:07

标签: java arrays json android-recyclerview android-json

JSONArray moviesArray = jsonObject.getJSONArray("Movies");
for (int j = 0; j < moviesArray.length(); j++) 
{
JSONObject moviesObject = moviesArray.getJSONObject(j);
JSONArray marvelArray = moviesObject.getJSONArray("Marvel");
JSONArray dccArray = moviesObject.getJSONArray("DC COMICS");
 .......
for (int k = 0; k < (DOUBT HERE).length(); k++)
{
JSONObject moviesJsonObj = (DOUBT HERE).getJSONObject(k);
String movieName = moviesJsonObj.getString("Release Year");
String releaseYear = moviesJsonObj.getString("DeityName");
Movies movies = new Movies(movieName, releaseYear)
moviesList.add(movies);
moviesAdapter= new moviesAdapter(moviesList);
recyclerView_Marvel.setAdapter(moviesAdapter);
recyclerView_DCComics.setAdapter(moviesAdapter); 

问题     我已将Marvel电影存储在Marvel数组中并将DC电影存储在DC中     数组。     现在我需要将这两个数组都传递到另一个类中以进行提取      电影名称和发行年份,然后将其放入回收站     view.i只能使用一个数组(marvel或dc),并且     将其显示在回收站中。您能帮我头同时使用     阵列并在两个单独的回收器视图中显示     我的JSON是

 {
    "Movies": [
        "Marvel": [{
                "MovieName": "IRON MAN",
                "Release Year": "2008"
            },
            {
                "MovieName": "THOR ",
                "Release Year": "2011"
            }
        ],
        "DC COMICS": [{
                "MovieName": "The Dark Knight",
                "Release Year": "2008"
            },
            {
                "MovieName": "Green Lantern ",
                "Release Year": "2011"
            }
        ]
    ]
}

0 个答案:

没有答案