【发布时间】:2025-12-12 18:35:01
【问题描述】:
嗨,我有一个 wcf json 格式的代码,我收到一个错误“json 中的语法错误意外令牌
//Details = Details.Replace(',', '.');
String[] UpdateUserDetails = new String[15];
// insertUserDetails = Details.Split('~');
using (OleDbConnection connection1 = new OleDbConnection())
{
connection1.ConnectionString = connectionString;
connection1.Open();
OleDbCommand command = connection1.CreateCommand();
//Check user exits
OleDbCommand cmdcheck = new OleDbCommand();
cmdcheck.CommandText = "select count(*) from usermaster where Username='" + UpdateUserDetails[0] + "'";
cmdcheck.Connection = connection1;
int iReturn = Convert.ToInt16(cmdcheck.ExecuteScalar());
if (iReturn <= 0)
{
string sqlUpdate = "UPDATE usermaster SET UserID= '100', UserName='" +
details.Split('~')[0] + "', Password = '" + details.Split('~')[1] + "', FirstName = '" + details.Split('~')[2] + "',LastName = '"
+ details.Split('~')[3] + "', Email = '" + details.Split('~')[4].Replace('#', '.') + "', MobileNo = '" + details.Split('~')[5] + "', UserType = '"
+ details.Split('~')[6] + "', UserGroup = '" + details.Split('~')[7] + "', PlantLocation = '" + details.Split('~')[8] + "', Department = '"
+ details.Split('~')[9] + "', Designation = '" + details.Split('~')[10] + "',Approved = 'No' ";
OleDbCommand cmdUpdate = new OleDbCommand();
cmdUpdate.CommandText = sqlUpdate;
cmdUpdate.Connection = connection1;
int x = cmdUpdate.ExecuteNonQuery();
cmdUpdate.Dispose();
if (x == 1)
return "User Updated Successfully";
else
return "User Updation failed";
}
else
{
return "User Name already exists";
}
}
}`
【问题讨论】:
-
分享代码,json,更好理解问题的东西。
-
该错误通常意味着端点正在从请求中返回 HTML 或 XML,而不是您期望的 JSON。检查 responseText,因为它很可能是由服务器上的错误引起的
-
我已经共享了 json 和 wcf 代码@MilanChheda
标签: javascript jquery json wcf twitter-bootstrap-3