I'm new to flutter and was working with json. when I am decoding the response I got from the server by using json.decode() I sometimes get the following error
flutter: FormatException: Unexpected character (at character 21)
sometimes it works perfectly.
this is my code
try {
Map<String, dynamic> map = new Map<String, dynamic>.from(
json.decode(contents));
if (map["CompletedJobPackages"] != null) {
DataStream.compleatedJobspackage =
DataStream.parseCompletedJobs(map["CompletedJobPackages"]);
print(map["CompletedJobPackages"]);
compleatedJobs = DataStream.compleatedJobspackage;
}
CompletedJobloaded = true;
}
catch(e){
print(e);
ToastUtils.showCustomToast(context, "An Error Occured. Try Again !", false);
}
this is the object I'm trying to decode
{
"CompletedJob": {
"CompletedJobID": 7,
"DriverID": 34,
"JobNumber": "80252C20",
"TraderID": 7,
"TripType": "Two Way",
"CargoType": "wd",
"CargoWeight": 230,
"LoadingPlace": "dc",
"UnloadingPlace": "sd",
"LoadingDate": "2020-05-25",
"LoadingTime": "12:59:00",
"EntryExit": 1,
"AcceptedDelay": 4,
"Price": 34,
"Created": "2020-05-23T04:22:10.000Z"
},
"BillPaid": 0,
"DriverReview": {
"DriverReviewID": 11,
"DriverID": 34,
"TraderID": 7,
"CompletedJobID": 7,
"Rating": 100,
"Review": "dscsdc",
"Created": "2020-05-28"
}
},