【发布时间】:2021-12-27 18:59:34
【问题描述】:
我想从保存在“消息”中的 API 获取图片链接,但我不断收到相同的异常。
我怎样才能得到“消息”以及为什么它会抛出这个异常。
我的 API
{"message":"https:\/\/images.dog.ceo\/breeds\/sheepdog-english\/n02105641_277.jpg","status":"success"}
API LINK: https://dog.ceo/api/breeds/image/random
我的方法
Future<void> loadDog() async {
try {
final response =
await http.get(Uri.parse("https://dog.ceo/api/breeds/image/random"));
final extractedData = json.decode(response.body) as Map<String, dynamic>;
extractedData.forEach((id, data) {
print(data["message"].toString());
});
} catch (err) {
print("ERROR = " + err.toString());
}
我的错误
ERROR = Expected a value of type 'int', but got one of type 'String'
【问题讨论】:
标签: json flutter api dart exception