尽量详细说明我的问题。以下是我的代码。
<script>
var dealers = new Array();
dealers.push(new Array("123", "870503-23-5370", "021"));
dealers.push(new Array("456", "830503-23-5371", "031"));
dealers.push(new Array("789", "870103-11-5372", "041"));
dealers.push(new Array("654", "870501-23-5373", "051"));
dealers.push(new Array("321", "880503-12-5374", "061"));
dealers.push(new Array("987", "870803-23-5375", "071"));
dealers.push(new Array("109", "870508-06-5376", "081"));
dealers.push(new Array("174", "810503-03-5377", "091"));
dealers.push(new Array("509", "870103-01-5378", "101"));
dealers.push(new Array("687", "870501-12-5379", "131"));
$(document).ready( function() {
$('#btnSubmit').click(function() {
$.ajax({
type: "post",
url: "DailyCheck.asmx/DailyCheckDealer",
data: JSON.stringify({ records: dealers }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
failure: onError
});
});
})
function onSuccess(response) {
alert(response.d);
}
function onError() {
alert("fail");
}
</script>
DailyCheck.asmx
Public Class DailyCheck
Inherits System.Web.Services.WebService
Public Class Dealer
Public IDNo, ICFound, POFound As String
End Class
<WebMethod()> _
Public Function DailyCheckDealer(records As String()()) As List(Of Dealer)
Dim mylist As List(Of String()) = records.ToList()
Dim datarow As String = ""
For i As Integer = 0 To mylist.Count - 1
Dim m As String() = mylist(i)
For j As Integer = 0 To m.Length - 1
datarow += m(j) + " "
result = datarow
Next
Next
' Insert the array into the database.
Dim myConnString = System.Configuration.ConfigurationManager.AppSettings("Conn")
Dim myConnection1 = New SqlConnection(myConnString)
Dim myCommand = New SqlCommand()
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Connection = myConnection1
myCommand.CommandText = "DailyCheckDealer"
myCommand.Parameters.Add("@DataRow", SqlDbType.VarChar, 8000).Value = datarow
myConnection1.Open()
myCommand.ExecuteNonQuery()
myConnection1.Close()
Dim myConnection2 = New SqlConnection(myConnString)
Dim objComm As New SqlCommand("Select IDNo, IDFound, POFound From DailyDealerCheck Order By IDNo", myConnection2)
Dim dealerList As New List(Of Dealer)()
myConnection2.Open()
Dim sdr As SqlDataReader = objComm.ExecuteReader()
While sdr.Read()
Dim objDealer As New Dealer()
objDealer.IDNo = sdr("IDNo").ToString()
objDealer.ICFound = sdr("IDFound").ToString()
objDealer.POFound = sdr("POFound").ToString()
dealerList.Add(objDealer)
End While
Return dealerList
End Function
萤火虫:发布值:
{ “记录”:[[ “123”, “870503-23-5370”, “021”],[ “456”, “830503-23-5371”, “031”],[ “789”, “870103-11-5372”, “041” ],[ “654”, “870501-23-5373”, “051”],[ “321”, “880503-12-5374”, “061”],[ “987”, “870803-23-5375” “071”],[ “109” “870508-06-5376”, “081”],[ “174”, “810503-03-5377”, “091”],[ “509”, “870103-01-5378”, “101”], [ “687”, “870501-12-5379” , “131”]]}
MSSQL:选择结果:
从上面的代码给了我,因为它使用alert(); :
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object对象
Firebug:响应值为:
{ “d”:[{ “__类型”: “DailyCheckDealer.DailyCheck +经销商”, “IDNO”: “109”, “ICFound”: “0”, “POFound”: “0”},{“__类型“ : “DailyCheckDealer.DailyCheck +经销商”, “IDNO”: “123”, “ICFound”: “1”, “POFound”: “1”},{ “__类型”:“DailyCheckDealer .DailyCheck +经销商 “ ”IDNO“: ”174“, ”ICFound“: ”0“, ”POFound“: ”0“},{ ”__类型“:” DailyCheckDealer.DailyCheck +经销商”, “IDNO”: “321”, “ICFound”: “0”, “POFound”: “0”},{ “__类型”: “+ DailyCheckDealer.DailyCheck经销商”, “IDNO” : “456”, “ICFound”: “0”, “POFound”: “1”},{ “__类型”: “+ DailyCheckDealer.DailyCheck经销商”, “IDNO”: “509”, “ICFound” : “0”, “POFound”: “0”},{ “__类型”: “+ DailyCheckDealer.DailyCheck经销商”, “IDNO”: “654”, “ICFound”: “0”, “POFound” : “1”},{ “__类型”: “+ DailyCheckDealer.DailyCheck经销商”, “IDNO”: “687”, “ICFound”: “0”, “POFound”: “0”},{ “__类型” : “DailyCheckDealer.DailyCheck +经销商”, “IDNO”: “789”, “ICFound”: “0”, “POFound”: “0”},{ “__类型”:“DailyCheckDealer .DailyCheck +经销商”, “IDNO”: “987”, “ICFound”: “0”, “POFound”: “0”}]}
我的问题:
"__type":"DailyCheckDealer.DailyCheck+Dealer"
作为返回值。{ “响应”:[[ “123”, “1”, “1”],[ “456”, “0”, “0”],[ “789”, “0”, “0”] ,[ “654”, “0”, “1”],[ “321”, “1”, “0”],[ “987”, “0”, “1”],[ “109”,“0 ”, “0”],[ “174”, “1”, “0”],[ “509”, “0”, “0”],[ “687”, “1”, “0”]]}
来自网络服务的预期回报值:
<Dealer>
<IDNo>123</IDNo>
<IcFound>0</IcFound>
<POFound>1</POFound>
</Dealer>
<Dealer>
<IDNo>456</IDNo>
<IcFound>1</IcFound>
<POFound>1</POFound>
</Dealer>
...........