Json.decode hang while parsing Flutter

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 stuck here and does not produce the result.

1 answer

  • answered 2019-01-11 06:01 iPatel

    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