簡體   English   中英

SyntaxError:JSON.parse:JSON數據的第1行第2列出現意外字符

[英]SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

調節器

[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;
});

我得到以下錯誤:

SyntaxError:JSON.parse:JSON數據的第1行第2列出現意外字符

另外,如果我想要對象中的成功和消息,如何在控制器actionresult中將對象作為json傳遞。

您將返回具有2個屬性( SuccessMessage json(不需要parseJSON )。 要訪問它們

success: function (result) {
  var success = result.Success;
  var message = result.Message;
  ....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM