Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将JsonArray解析为自定义数组_Android_Json_Gson - Fatal编程技术网

Android 将JsonArray解析为自定义数组

Android 将JsonArray解析为自定义数组,android,json,gson,Android,Json,Gson,我正在尝试使用gson将jsonarray解析为自定义数组。这就是我到现在为止所做的 try { String jsonData = response.body().string(); JSONObject mObject = new JSONObject(jsonData); JSONArray movies = mObject.getJSONArray("results"); Type listType = new Type

我正在尝试使用gson将jsonarray解析为自定义数组。这就是我到现在为止所做的

try {
        String jsonData = response.body().string();
        JSONObject mObject = new JSONObject(jsonData);

        JSONArray movies = mObject.getJSONArray("results");

        Type listType = new TypeToken<List<Movie>>(){}.getType();
        List<Movie> movieList = mGson.fromJson(movies.toString(), listType);

     } catch (IOException e) {
                Log.d(TAG + " Failure 1", e.getMessage());
     } catch (JSONException e) {
                Log.d(TAG + " Failure 2", e.getMessage());
     }
}
这是JSONArray的一个值

{"vote_count":1126,"id":337167,"video":false,"vote_average":6.1,"title":"Fifty Shades Freed","popularity":542.892558,"poster_path":"\/jjPJ4s3DWZZvI4vw8Xfi4Vqa1Q8.jpg","original_language":"en","original_title":"Fifty Shades Freed","genre_ids":[18,10749],"backdrop_path":"\/9ywA15OAiwjSTvg3cBs9B7kOCBF.jpg","adult":false,"overview":"Believing they have left behind shadowy figures from their past, newlyweds Christian and Ana fully embrace an inextricable connection and shared life of luxury. But just as she steps into her role as Mrs. Grey and he relaxes into an unfamiliar stability, new threats could jeopardize their happy ending before it even begins.","release_date":"2018-02-07"}

{"vote_count":6697,"id":269149,"video":false,"vote_average":7.7,"title":"Zootopia","popularity":340.221253,"poster_path":"\/sM33SANp9z6rXW8Itn7NnG1GOEs.jpg","original_language":"en","original_title":"Zootopia","genre_ids":[16,12,10751,35],"backdrop_path":"\/mhdeE1yShHTaDbJVdWyTlzFvNkr.jpg","adult":false,"overview":"Determined to prove herself, Officer Judy Hopps, the first bunny on Zootopia's police force, jumps at the chance to crack her first case - even if it means partnering with scam-artist fox Nick Wilde to solve the mystery.","release_date":"2016-02-11"}

你有电影课。将“电影”添加到字段是多余的

默认情况下,所有JSON键必须与Java字段完全匹配,Gson才能工作

例如,
movieoriginalttle
应改为
original\u title


总的来说,我建议您阅读

到底是什么问题?Gson自动解析请将您的JSON数据和电影类添加到问题JSON数据?Gson要求您通过way@cricket_007我更新了information,为什么你的电影类中没有JSON的每个字段?
{"vote_count":1126,"id":337167,"video":false,"vote_average":6.1,"title":"Fifty Shades Freed","popularity":542.892558,"poster_path":"\/jjPJ4s3DWZZvI4vw8Xfi4Vqa1Q8.jpg","original_language":"en","original_title":"Fifty Shades Freed","genre_ids":[18,10749],"backdrop_path":"\/9ywA15OAiwjSTvg3cBs9B7kOCBF.jpg","adult":false,"overview":"Believing they have left behind shadowy figures from their past, newlyweds Christian and Ana fully embrace an inextricable connection and shared life of luxury. But just as she steps into her role as Mrs. Grey and he relaxes into an unfamiliar stability, new threats could jeopardize their happy ending before it even begins.","release_date":"2018-02-07"}

{"vote_count":6697,"id":269149,"video":false,"vote_average":7.7,"title":"Zootopia","popularity":340.221253,"poster_path":"\/sM33SANp9z6rXW8Itn7NnG1GOEs.jpg","original_language":"en","original_title":"Zootopia","genre_ids":[16,12,10751,35],"backdrop_path":"\/mhdeE1yShHTaDbJVdWyTlzFvNkr.jpg","adult":false,"overview":"Determined to prove herself, Officer Judy Hopps, the first bunny on Zootopia's police force, jumps at the chance to crack her first case - even if it means partnering with scam-artist fox Nick Wilde to solve the mystery.","release_date":"2016-02-11"}