我使用这段代码将散列映射数据解析为flatter中的一个对象:
factory Channel.fromMap(Map<String, dynamic> json) => Channel(
id: json["id"],
author: json["author"] == null ? "" : json["author"],
deleted: json["deleted"] == null ? false : json["deleted"],
content: json["content"] == null ? "" : json["content"],
dead: json["dead"] == null ? false : json["dead"],
poll: json["poll"] == null ? null : json["poll"],
parent: json["parent"] == null ? null : json["parent"],
parts: json["parts"] == null
? []
: List<int>.from(json["parts"].map((x) => x)),
descendants: json["descendants"] == null ? 0 : json["descendants"],
kids: json["kids"] == null
? []
: List<int>.from(json["kids"].map((x) => x)),
score: json["score"] == null ? 0 : json["score"],
pubTime: json["pubTime"] == null ? 0 : json["pubTime"],
title: json["title"] == null ? "" : json["title"],
subName: json["subName"] == null?"":json["subName"],
subUrl: json["subUrl"] == null?"":json["subUrl"],
isFav: json["isFav"] == null?"":json["isFav"],
intro: json["intro"] == null?"":json["intro"],
);
当代码运行到此行时
isFav: json["isFav"] == null?"":json["isFav"],
对于代码,只需跳转并不返回任何内容,没有错误输出,我应该怎么做来解决这个问题?
static List<Channel> convertTheResult(Response response) {
if (RestClient.respSuccess(response)) {
var channelResult = response.data["result"];
if (channelResult == null) {
return null;
}
var channelListResult = channelResult["list"];
List<Channel> channels = [];
channelListResult.forEach((element) {
try {
Channel parsedChannel = Channel.fromMap(element);
if (parsedChannel != null) {
channels.add(parsedChannel);
}
} on Exception catch (e) {
CruiseLogHandler.logError(CruiseApiError('Channel parsed failed.'), JsonEncoder().convert(response));
}
});
return channels;
}
}
仍然没有捕捉到任何异常线索。