我需要能够在我的 ASP.NET 应用程序中通过 AJAX 将字符串数组和字符串数组的数组传递给 Web 服务。但我不断得到
{"Message":"Invalid object passed in, : or } expected. (16): { basicInfo:\"[\"TESTCO\",\"TESTCO\",\"PO BOX 0\",\"My City\",\"MyState\",\"My Zip\",\"MyPhone\",\"TEST1 - TEST, TEST3 - TEST, \",\"11/15/2012\",\"16:36\",\"myname\",\"1202160021\"]\"}","StackTrace":" 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[T](String input)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
我对 JSON 和序列化以及所有这些都不是很了解。所以我真的不知道我做错了什么。
var cvwOther = new Array();
var equipAssign = new Array();
var qAndA = new Array();
var binfo = new Array(storeinfo[2], storeinfo[6], storeinfo[7], storeinfo[8], storeinfo[9],
storeinfo[10], storeinfo[11], storeinfo[12], getToday(), getNow(), userinfo[0], call);
function submitCVW(call) {
db.transaction(function (tx) {
tx.executeSql("Select * From CVWOther Where CallNumber=?", [call], function (tx, result) {
var i = 0;
$.each(result.rows, function () {
cvwOther[i] = result.rows.item(i);
i++;
});
}, onSQLError);
tx.executeSql("Select * From EquipAssign Where CallNumber=?", [call], function (tx, result) {
var i = 0;
$.each(result.rows, function () {
equipAssign[i] = result.rows.item(i);
i++;
});
}, onSQLError);
tx.executeSql("Select * From CVW Where CallNumber=?", [call], function (tx, result) {
var i = 0;
$.each(result.rows, function () {
qAndA[i] = result.rows.item(i);
i++;
});
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json",
url: "MyService.asmx/CVW",
data: '{ basicInfo:"' + JSON.stringify(bInfo) + '", cvwOther:"' + JSON.stringify(cvwOther) + '"}',
success: function(data) {
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}, onSQLError);
});
}
Web 方法签名
[WebMethod]
public void SubmitCVW(string[] basicInfo, string[][] cvwOther)