【发布时间】:2020-07-09 08:00:52
【问题描述】:
我正在开发一个颤振应用程序,我有一个来自 API 的 JSON 数组,它包含列表数组中的对象,所以我需要获取数组中的最后一个对象并将最后一个对象推送到新数组因为我需要返回它将数组列表放入列表视图以显示...我该怎么做
我的代码
main() {
var data = json.decode('[ {"id":42,"image_path":"https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1583971227.jpg","hall_details":"*********"},
{"id":52,"image_path":"https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584390666.jpg",
"hall_details":" Could anyone please help me with this. I am stuck here. Have been trying different methods but none working. Thank you"},
{"id":62,
"image_path":"https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
"hall_details":"Could anyone please help me with this. I am stuck here. Have been trying different methods but none working. Thank you."},
{"id":65,
"image_path":"https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
"hall_details":"Could anyone please help me with this. I am stuck here. Have been trying different methods but none working. Thank you."}]');
Map responseJson = data[data.length-1];
List returnMovies = [];
returnMovies.addAll({responseJson});
print(returnMovies);
}
【问题讨论】: