Json.decode hangs while parsing JSON in Flutter

Viewed 1630

The body of my response contains the following data

[{"AttendanceID":null,"MobilePrefID":"Ab12949","DateTimeInString":"08/01/2019","DateTimeOutString":"08/01/2019","TimeIn":"18:16","TimeOut":"18:18","SignInAddress":null,"SignOutAddress":null}]

My code to decode to JSON is as follow

var dec = json.decode(resp.body)

However, the command gets stuck here and does not produce the result.

1 Answers

Got reference from

"Unexpected Character" on Decoding JSON

And tried your code as

 JsonCodec codec = new JsonCodec();
  try{
    String strBody = """[{"AttendanceID":null,"MobilePrefID":"Ab12949","DateTimeInString":"08/01/2019","DateTimeOutString":"08/01/2019","TimeIn":"18:16","TimeOut":"18:18","SignInAddress":null,"SignOutAddress":null}]""";
    print(strBody);
    var decoded = codec.decode(strBody);
    print("Decoded 1: $decoded");
  } catch(e) {
    print("Error: $e");
  }

You will be got result

Related