0

I am a bit new to flutter and I am getting the message

E/flutter (26774): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter (26774): <br />
E/flutter (26774): ^

In my console when connecting api's for a registration form, this is what I have in my code

  Future RegistrationUser() async {
    var APIURL = "http://192.168.1.2/xxxxxxxxx/api/xxxxxxx.php";

    Map mapeddate = {
      'name': _name.text,
      'phone': _phone.text,
      'email': _email.text,
      'pass': _pass1.text,
      'type': "applicant",
    };
    print("JSON DATA: $mapeddate");

    http.Response response =
        await http.post(Uri.parse(APIURL), body: mapeddate);

    var data = jsonDecode(response.body);

    print("DATA: ${data}");
  }
}

Does anyone know how I can fix this? Any help would be much appreciated.

Panashe
  • 99
  • 1
  • 10
  • Your code seems fine. Is there any file with the text shown in your error message (
    ). Your error seems to point to that opening angular bracket, maybe you added that line somewhere by mistake.
    – Novice Coder Apr 24 '22 at 13:35
  • 1
    Your API is returning HTML rather than JSON. You need to find out why and fix it - perhaps your request is malformed. – Richard Heap Apr 24 '22 at 13:35
  • Hmmm no I'm sure there's no bracksts anywhere except in the link for the api call itself, and also I' sure that the API is returning JSON format but I don't know where the problem is. – Panashe Apr 25 '22 at 07:40

1 Answers1

0

jsonDecode() can only parse JSON format. The response from the http request that you've made contains <br/> - which is an invalid value in JSON. What you can do here is parse the HTML String response and fetch the elements - which what I'm guessing that you might need since a sample of the response that you're parsing wasn't provided.

Omatt
  • 8,564
  • 2
  • 42
  • 144