Arrays 如何获取json数组中的最后一个对象并插入到新数组中

Arrays 如何获取json数组中的最后一个对象并插入到新数组中,arrays,json,flutter,Arrays,Json,Flutter,我正在开发一个颤振应用程序,我有一个JSON数组,它来自API,它是列表数组中的include对象,所以我需要获取数组中的最后一个对象,并将最后一个对象推到新数组中,因为我需要将数组列表返回到列表视图中以显示。。。我该怎么做 我的代码 main(){ var data=json.decode(“[{”id“:42,“图像路径”:”https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1583971227.jpg,“大厅详细信息

我正在开发一个颤振应用程序,我有一个JSON数组,它来自API,它是列表数组中的include对象,所以我需要获取数组中的最后一个对象,并将最后一个对象推到新数组中,因为我需要将数组列表返回到列表视图中以显示。。。我该怎么做

我的代码

main(){
var data=json.decode(“[{”id“:42,“图像路径”:”https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1583971227.jpg,“大厅详细信息”:“********”},
{“id”:52,“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584390666.jpg",
“hall_细节”:“谁能帮我一下吗?我被困在这里了。一直在尝试不同的方法,但都不管用。谢谢”},
{“id”:62,
“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
“hall_细节”:“有谁能帮我一下吗?我被困在这里了。我一直在尝试不同的方法,但都不管用。谢谢。”,
{“id”:65,
“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
“hall_细节”:“谁能帮我一下吗?我被困在这里了。一直在尝试不同的方法,但都不管用。谢谢。”}]”;
Map responseJson=data[data.length-1];
列表返回电影=[];
returnMovies.addAll({responseJson});
印刷品(电影);
}          

一般的答案是使用这个库

它不仅对这种情况有帮助,而且对所有Dart对象=>JSON=>Dart对象情况都有帮助

请先仔细阅读图书馆自述文件,特别是“基本设置”部分

下面的代码将帮助您掌握主要思想:

import'main.reflectable.dart'show initializeReflectable;
导入“包:dart_json_mapper/dart_json_mapper.dart”显示jsonSerializable、JSONMappedPter、typeOf、JsonMapper、反序列化选项、CaseStyle;
@jsonSerializable
班级电影{
int-id;
字符串图像路径;
字符串详细信息;
}
真空总管{
初始化可反射();
//给定
最终json=
'[{“id”:42,“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1583971227.jpg,“大厅详细信息”:“********”},
{“id”:52,“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584390666.jpg",
“hall_细节”:“谁能帮我一下吗?我被困在这里了。一直在尝试不同的方法,但都不管用。谢谢”},
{“id”:62,
“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
“hall_细节”:“有谁能帮我一下吗?我被困在这里了。我一直在尝试不同的方法,但都不管用。谢谢。”,
{“id”:65,
“图像路径”:https://fathomless-brushlands-95996.herokuapp.com/Imaga_halls/1584453580.jpg",
“hall_细节”:“有谁能帮我一下吗?我被困在这里了。一直在尝试不同的方法,但都不管用。谢谢。”}]“”;
JsonMapper().useAdapter(JsonMapperAdapter(valueDecorators:{
typeOf():(value)=>value.cast()
}));
//什么时候
final moviesList=JsonMapper.deserialize(
json,反序列化选项(caseStyle:caseStyle.Snake));
//然后
expect(moviesList.last,TypeMatcher());
打印(moviesList.last.id);
打印(moviesList.last.hallDetails);
打印(moviesList.last.imagePath);
}

非常感谢兄弟