我试图通过int.parse函数将String变量更改为int,但是我一直收到错误=> '[VERBOSE-2:ui_dart_state.cc(157)]未处理的异常:FormatException:无效的基数36数字(在字符1处) 83059 ^'
我尝试了int.tryParse,但不会显示所有数据。
void getData() async {
String jsonURL =
'https://interactive-static.scmp.com/sheet/wuhan/viruscases.json?fbclid=IwAR2x0mm3kcJJElCMDWr18Lvjyoh6B1XLamvX1Hecf_7Tw7XO7Oy5OG3wBFM';
var client = Client();
Response response2 = await client.get(jsonURL);
var decodedData = json.decode(utf8.decode(response2.bodyBytes));
totalNumber = decodedData['entries'].length;
lastUpdated = decodedData['last_updated'].substring(0, 10);
for (var i = 0; i < decodedData['entries'].length; i++) {
String tempString = decodedData['entries'][i]['cases'];
String tempDeath = decodedData['entries'][i]['deaths'];
//To remove the commas so I can parse it to int variable
tempDeath = tempDeath.replaceAll(',', '');
tempString = tempString.replaceAll(',', '');
//
//Adding to a List<CovidData>
listOfData.add(
CovidData(
country: decodedData['entries'][i]['country'],
cases: tempString,
recovered: decodedData['entries'][i]['recovered'],
death: tempDeath),
);
}
//Sorting via int
listOfData.sort((b, a) => int.parse(a.cases).compareTo(int.parse(b.cases)));
setState(() {});
unTouchedData = listOfData;
}