data.d
=
[
{
"NodeId": "BK01",
"NodeName": "Books",
"ParentId": null,
"Likes": null
},
{
"NodeId": "CO01",
"NodeName": "Computers",
"ParentId": null,
"Likes": null
},
{
"NodeId": "GA01",
"NodeName": "Gaming",
"ParentId": null,
"Likes": null
},
{
"NodeId": "MO01",
"NodeName": "Mobile & Accessories",
"ParentId": null,
"Likes": null
}
]
ウェブサービス
<WebMethod()> _
Public Shared Function getCategories() As String
Dim details As New List(Of Nodes)()
Dim index As New Default2
Using ds As Data.DataSet = index.db.ExecuteDataSet(CommandType.Text, "SELECT NodeID,NodeName FROM Nodes WHERE ParentID='1'")
Dim JaggedArray As String()() = New String(ds.Tables(0).Rows.Count - 1)() {}
Dim i As Integer = 0
For Each rs As DataRow In ds.Tables(0).Rows
Dim node As New Nodes()
node.NodeId = rs("NodeId").ToString
node.NodeName = rs("NodeName").ToString
details.Add(node)
'JaggedArray(i) = New String() {rs("NodeName").ToString(), rs("NodeID").ToString()}
i = i + 1
Next
End Using
Dim js As New JavaScriptSerializer()
Dim strJSON As String = js.Serialize(details.ToArray)
Return strJSON
End Function
AJAX 呼び出し
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//alert("!!!");
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default2.aspx/getCategories",
data: "{}",
dataType: "json",
success: function(data) {
var nodes = eval(data);
alert(data.NodeName);
$('#output').text(data.d);
$.each(data.d, function(index, node) {
$('#output').append('<p><strong>' + node.NodeName + ' ' +
node.NodeID + '</strong><br /> ');
});
},
error: function(result) {
alert("Error");
}
});
});
</script>
値を取得するためにループする方法はdata.d
? data.d.length
私に与えます219
が、それは 4 でなければなりませんか?私は何を間違っていますか??