我疯了。也许有人可以帮忙。
我在网站上将我的ajax传递给后端的asmx。
数据如此。它是有效的json。 http://jsonlint.com/
{ "data": [{"Address":"addasdf","City":"casdf","County":"casdf","State":"dc","Zip":"33333","ReferenceID":"asdf","LegalDescription":"asdf","PreviousOwner":"asdf","ClientNotes":"sadf","AcquisitionType":"sadf","ClientAcquisitionDate":"asdf","ForeclosureDate":"asdf"}]}
发送数据的ajax就在这里。据我所知,这是正确的发送,是对的。
$.ajax({
type: "POST",
url: "/ServiceFolder/BulkOrder.asmx/insertBulk",
data: "{ \"data\": " + smyData + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, textStatus, jqXHR) { //
//alert(data);
console.log(data);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
console.log(xmlHttpRequest.responseText);
console.log(textStatus);
console.log(errorThrown);
alert("Screen shot this error getEntityMarkers: " + xmlHttpRequest.toString() + " " + textStatus.toString() + " " + errorThrown.toString());
}
});
我的班级为发送的数据建模。
[Serializable]
public class BulkOrderObject
{
public List<BulkOrderObjectData> data { get; set; }
}
[Serializable]
public class BulkOrderObjectData
{
public string Address { get; set; }
public string City { get; set; }
public string County { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string ReferenceID { get; set; }
public string LegalDescription { get; set; }
public string PreviousOwner { get; set; }
public string ClientNotes { get; set; }
public string AcquisitionType { get; set; }
public string ClientAcquisitionDate { get; set; }
public string ForeclosureDate { get; set; }
}
最后我认为我的问题出在网络方面。
[WebMethod]
public string insertBulk(List<BulkOrderObject> data)
{
string myreturn = String.Empty;
myreturn += data.Count; // data returns count
//List<BulkOrderObject> l = data as List<BulkOrderObject>;
try
{
foreach (var i in data)
{
myreturn += i.data.Count; // error here.
}
}
catch (Exception ex)
{
myreturn += ex.ToString();
}
return myreturn;
}
当我尝试获取data.count中的条目数时,在公共字符串insertBulk(List&lt; BulkOrderObject&gt;数据)中出现了一些时髦的东西,它表明那里有1.但是当我尝试foreach时数据中的数据会返回错误。
{"d":"1System.NullReferenceException: Object reference not set to an instance of an object.\r\n at
test.insertBulk(List`1 data)"}
好像它没有填满BulkOrderObjectData。
有什么想法吗?