我正在解析此JSON:

{
 "poster_path":"\/vZpB8ezB1IqpxI9rx553TuGwDzJ.jpg",
 "overview":"Thirty years after defeating the Galactic Empire, Han Solo and his allies face a new threat from the evil Kylo Ren and his army of Stormtroopers.",
 "release_date":"2015-12-15",
 "genre_ids":[  ],
 "id":140607,
 "original_title":"Star Wars: The Force Awakens",
 "original_language":"en",
 "title":"Star Wars: The Force Awakens",
 "vote_average":7.65
}


我可以解析我想要的所有属性

overview=movieForecast.getString(OVERVIEW);
original_title = movieForecast.getString(ORIGINAL_TITLE);
movie_poster= movieForecast.getString(POSTER_PATH);
user_rating = movieForecast.getDouble(VOTE_AVERAGE);
release_date  = movieForecast.getInt(RELEASE_DATE);


但是我对user_rating和发布日期有问题,但是我可以通过将getString方法更改为getDouble来修复user_rating

但是我不能在发布日期上做同样的事情(getDouble,getInteger,getString)不起作用!

最佳答案

我不知道您的release_date是否为Date对象。
如果是,则可以使用SimpleDateFormatter



String date = movieForecast.getString("release_date");
SimpleDateFormatter sdf = new SimpleDateFormatter("yyyy-mm-dd");
Date releaseDate = sdf.parse(date);

movieForecast.setDate(releaseDate); //example

10-06 12:55