语法错误:JSON.parse:在JSON数据线1列2意外的字符 [英] SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
本文介绍了语法错误:JSON.parse:在JSON数据线1列2意外的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
控制器
[HttpGet]
public ActionResult VerifyUserEmail(string User_Email)
{
try
{
using (EmptyMVCApplicationEntities objConnection = new EmptyMVCApplicationEntities())
{
ObjectParameter objIErrorCode = new ObjectParameter("ErrorCode", typeof(Int32));
ObjectParameter objBFlag = new ObjectParameter("bFlg", typeof(bool));
objConnection.Check_User_Exists(User_Email, objBFlag, objIErrorCode);
if (Convert.ToBoolean(objBFlag.Value) != true)
{
return Json(new { Success = "false", Message = "Email exists" }, JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { Success = "True", Message = "Email not exists" }, JsonRequestBehavior.AllowGet);
}
}
}
catch (Exception Ex)
{
}
}
剧本
$("#User_Email").blur(function () {
if ($(this).val() != "") {
$.ajax({
url: "/User/VerifyUserEmail?User_Email=" + $("#User_Email").val(),
success: function (result) {
try {
var jsonIssueObj = $.parseJSON(result).Data;
} catch (e) { alert(e); }
if (!jsonIssueObj.Success) {
var errorMsg = jsonIssueObj.Message;
$('#msg').html(errorMsg);
$('#msg').show();
}
else {
var errorMsg = null;
$('#msg').html(errorMsg);
$('#msg').hide();
}
}
});
}
return false;
});
我收到以下错误:
I am getting below error:
语法错误:JSON.parse:第1行的JSON数据第2栏意外的字符
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
另外,如果我想成功和消息中的对象,如何传递一个对象作为控制器的ActionResult JSON。
Also If I want Success and Message in an object, how to pass an object as json in controller actionresult.
推荐答案
您在返回与2个属性JSON,成功
和消息
(你不需要 parseJSON
)。要访问它们。
You returning json with 2 properties, Success
and Message
(you do not need parseJSON
). To access them
success: function (result) {
var success = result.Success;
var message = result.Message;
....
这篇关于语法错误:JSON.parse:在JSON数据线1列2意外的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文