有人知道为什么我会收到此错误消息吗?
错误信息:
{"Message":"Invalid JSON primitive: tab_group_48.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
jQuery:
可靠的 jQuery 看起来像这样:
$.ajax({
type: 'POST',
url: '/webservices/minimised.asmx/UpdateState',
data: '{ strTabID:' + tab + ', strWidgetID:' + widget[1] + ', intState:' + state + ' }',
发布到服务器的数据
在这个例子中:
数据变成={ strTabID:tab_group_48, strWidgetID:portlet_4, intState:0 }
C#:
而可靠的 webservice 部分 c# 如下所示:
[WebMethod()]
public int UpdateState(string strTabID, string strWidgetID, int intState)
{
intTabID = Convert.ToInt32(strTabID.Replace("tab_group_", ""));
strQuery = "update columns set unminimised = @state where tabs_id = @tab and widgets_id = @widget";
intWidgetID = Convert.ToInt32(strTabID.Replace("portlet_", string.Empty));
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand(strQuery, connection))
{
command.Parameters.Add("@tab", SqlDbType.Int, 4).Value = intTabID;
command.Parameters.Add("@widget", SqlDbType.Int, 4).Value = intWidgetID;
command.Parameters.Add("@state", SqlDbType.Int, 4).Value = intState;
connection.Open();
intAffectedRows = command.ExecuteNonQuery();
connection.Close();
}
}
return intAffectedRows;
}