FormatException: 意外字符 (在字符 1) <br /> ^

huangapple go评论74阅读模式
英文:

FormatException: Unexpected character (at character 1) <br /> ^

问题

I will only translate the code portion for you:

&lt;!-- begin snippet: js hide: false console: true babel: false --&gt;

&lt;!-- language: lang-js --&gt;

validateUserEmail()  async
  {
    try
    {
      var res = await http.post(
       Uri.parse(API.validateEmail),
       body: {
         &#39;user_email&#39;: emailController.text.trim(),
       },
     );
     if(res.statusCode == 200)//The HTTP 200 OK success status response code
       // indicates that the request has succeeded.
     {
      var resBodyOfValidateEmail = jsonDecode(res.body);
      if(resBodyOfValidateEmail[&#39;emailFound&#39;] == true)
        {
         Fluttertoast.showToast(msg: &quot;Email already in use.&quot;);
        }
      else
      {
        //register and save new user to database
        registerAndSaveUserRecord();

      }

     }
    }
    catch(e)
    {
      print(e.toString());
      Fluttertoast.showToast(msg: e.toString());
    }
  }

  registerAndSaveUserRecord() async
  {
   User userModel = User(
     1,
     nameController.text.trim(),
     emailController.text.trim(),
     passwordController.text.trim(),
   );

   try
       {
      var res = await http.post(
         Uri.parse(API.signUp),
         body: userModel.toJson(),
       );
      if(res.statusCode == 200)
        {
       var resBodyOfSignUp = jsonDecode(res.body);
       if(resBodyOfSignUp[&#39;success&#39;] == true)
       {
         Fluttertoast.showToast(msg: &quot;You have signup successfully.&quot;);
       }
       else 
         {
           Fluttertoast.showToast(msg: &quot;Error try again&quot;);
         }
        }
       }
       catch(e)
    {
      print(e.toString());
      Fluttertoast.showToast(msg: e.toString());
    }
  }

&lt;!-- language: lang-html --&gt;

&lt;!-- end snippet --&gt;

Please note that some of the code is represented with HTML entities, which might need to be converted back to their original characters for code execution.

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

validateUserEmail()  async
{
try
{
var res = await http.post(
Uri.parse(API.validateEmail),
body: {
&#39;user_email&#39;: emailController.text.trim(),
},
);
if(res.statusCode == 200)//The HTTP 200 OK success status response code
// indicates that the request has succeeded.
{
var resBodyOfValidateEmail = jsonDecode(res.body);
if(resBodyOfValidateEmail[&#39;emailFound&#39;] == true)
{
Fluttertoast.showToast(msg: &quot;Email already in use.&quot;);
}
else
{
//register and save new user to database
registerAndSaveUserRecord();
}
}
}
catch(e)
{
print(e.toString());
Fluttertoast.showToast(msg: e.toString());
}
}
registerAndSaveUserRecord() async
{
User userModel = User(
1,
nameController.text.trim(),
emailController.text.trim(),
passwordController.text.trim(),
);
try
{
var res = await http.post(
Uri.parse(API.signUp),
body: userModel.toJson(),
);
if(res.statusCode == 200)
{
var resBodyOfSignUp = jsonDecode(res.body);
if(resBodyOfSignUp[&#39;success&#39;] == true)
{
Fluttertoast.showToast(msg: &quot;You have signup successfully.&quot;);
}
else 
{
Fluttertoast.showToast(msg: &quot;Error try again&quot;);
}
}
}
catch(e)
{
print(e.toString());
Fluttertoast.showToast(msg: e.toString());
}
}

<!-- language: lang-html -->

<!-- end snippet -->

Guys i keep getting this error in Android studio when i try to register a new user to my flutter application

The image shows the area where I think the problem is

I tried double checking the code to see whether there might be any typos or breaks on the code.

what might be the problem?

答案1

得分: 0

"it seems that you are trying to decode a json but the api is sending an html instead of a json string, so that's why it fails decoding. I would recommend to check what is the api sending to you before trying to decode the body."

英文:

it seems that you are trying to decode a json but the api is sending an html instead of a json string, so that's why it fails decoding. I would recommend to check what is the api sending to you before trying to decode the body.

huangapple
  • 本文由 发表于 2023年4月10日 22:00:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定