英文:
FormatException: Unexpected character (at character 1) <br /> ^
问题
I will only translate the code portion for you:
<!-- 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: {
'user_email': 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['emailFound'] == true)
{
Fluttertoast.showToast(msg: "Email already in use.");
}
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['success'] == true)
{
Fluttertoast.showToast(msg: "You have signup successfully.");
}
else
{
Fluttertoast.showToast(msg: "Error try again");
}
}
}
catch(e)
{
print(e.toString());
Fluttertoast.showToast(msg: e.toString());
}
}
<!-- language: lang-html -->
<!-- end snippet -->
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: {
'user_email': 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['emailFound'] == true)
{
Fluttertoast.showToast(msg: "Email already in use.");
}
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['success'] == true)
{
Fluttertoast.showToast(msg: "You have signup successfully.");
}
else
{
Fluttertoast.showToast(msg: "Error try again");
}
}
}
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论