Flutter dart type 'int' is not a subtype of type 'String'
很奇怪,今天收到这个报错,原因是我用 String
接收服务器返回Json
数据中的 int
类型。这在 JAVA 中是很常见的做法,String
可以接收字段类型是int
的数据。
现在要么我修改成 int
去接收,或者做以下处理,将 int
转成 String
。
StationEntity.fromJson(Map<String, dynamic> json) { stationId = json['stationId'].toString(); ... } stationId = json['stationId'] as String; 不行 stationId = json['stationId'].toString(); 可以
本文由老郭种树原创,转载请注明:https://guozh.net/type-int-is-not-a-subtype-of-type-string/