后端返回的接口,成功code == 200后,携带data,其中data里有一个名为dtoList的数组,我需要叠加dtoList的money字段,求出总金额,使用数组reduce方法,一直编译不过去:
[java.lang.ClassCastException] {cause: null, message: "io.dcloud.uts.UTSArray cannot be cast to io.dcloud.uts.UTSJSONObject"}
try {
const res = await getMedMoney();
if (res['code'] == 200) {
let resData = (res['data'] as UTSJSONObject);
let _listDto = resData['listDto'] as Array<UTSJSONObject>;
//这里一直报错:[java.lang.ClassCastException] {cause: null, message: "io.dcloud.uts.UTSArray cannot be cast to io.dcloud.uts.UTSJSONObject"}
let _allMoney = _listDto.reduce((prev : number, curr : UTSJSONObject) => {
return (curr['money'] as number) + prev;
}, 0)
console.log("_allMoney");
}
} catch (err : any) {
console.log("这里报错了!!!!!!")
console.error(err);
}
0 个回复