Flutter 解析本地json Unhandled Exception: type ‘_ByteDataView‘ is not a subtype of type ‘String‘ in type

报错:
Unhandled Exception: type ‘_ByteDataView’ is not a subtype of type ‘String’ in type cast

解决方法:
首先先检查路径是否正确,以及yaml配置路径是否正确。都正确可以看调用方法是否为loadString()。例如,我一开始使用的是:

String str = (await rootBundle.load("lib/dao/home_content.json")) as String;

就是有问题的,这里只需改成:

String str = await rootBundle.loadString("lib/dao/home_content.json");

即可。

猜你喜欢

转载自blog.csdn.net/kicinio/article/details/129904190