Home > Back-end >  FormatException (FormatException: Unexpected character (at character 1)
FormatException (FormatException: Unexpected character (at character 1)

Time:08-31

I am trying to get data from a json from a link and decode it to display data in a calendar, so it worked fine until this error appears in this line

dynamic jsonAppData = convert.jsonDecode(data.body);

Which trows this:

Exception has occurred. FormatException (FormatException: Unexpected character (at character 1) <!doctype html><base href="https://accou... ^ )

I don't really know why it is caused, I searched for solutions but I didn't find anything for my case.

I hope you can help me.

Future<List> getDataFromGoogleSheet() async { Response data = await http.get( Uri.parse( "https://script.google.com/macros/s/AKfycbybaFrTEBrxTIni8izFKMQYNNAe7ciVMlqF0OUHyWujjRR2AQ8zDyQzh96tleRKMHSN/exec"), );

dynamic jsonAppData = convert.jsonDecode(data.body);
final List<Meeting> appointmentData = [];

for (dynamic data in jsonAppData) {
  var recurrence = data['byday'];

  Meeting meetingData = Meeting(
    eventName: data['subject'],
    from: _convertDateFromString(data['starttime']),
    to: _convertDateFromString(data['endtime']),
    background: Colors.grey.shade800,
    recurrenceRule: 'FREQ=DAILY;INTERVAL=7;BYDAY:$recurrence;COUNT=10',
  );
  appointmentData.add(meetingData);
  String notes = data['notes'];
}
return appointmentData;   }

CodePudding user response:

Your response body is not of json type.

You should check your request before

CodePudding user response:

You can't parse the json because you have to authenticate with google first. If you call the page in the browser, where you are not logged in with Google, then you are redirected to the login page of Google. And my guess is this page is parsed, not the json.

  • Related