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.

3
  • Your code seems fine. Is there any file with the text shown in your error message (<br/>). Your error seems to point to that opening angular bracket, maybe you added that line somewhere by mistake. Commented Apr 24, 2022 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. Commented Apr 24, 2022 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. Commented Apr 25, 2022 at 7:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.