リクエストに次のコード スニペットを使用していますJSON
。
<WebMethod(Description:="Gets the Categories")> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function GetCategories() As String
Using ds As DataSet = db.ExecuteDataSet(CommandType.Text, "SELECT NodeID,NodeName FROM Nodes WHERE ParentID='1'")
' Create a multidimensional jagged array
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
JaggedArray(i) = New String() {rs("NodeName").ToString(), rs("NodeID").ToString()}
i = i + 1
Next
' Return JSON data
Dim js As New JavaScriptSerializer()
Dim strJSON As String = js.Serialize(JaggedArray)
Return strJSON
End Using
End Function
私が得る応答:
<string xmlns="http://localhost:54511/">
[["Books","BK01"],["Computers","CO01"],["Gaming","GA01"],["Mobile & Accessories","MO01"]]
</string>
なぜ私は取得しないのですkey
か??
例えば:
<string xmlns="http://localhost:54511/">
[{"nodename":"Books","nodeid":"BK01"},{"nodename":"Computers","nodeid":"CO01"},{"nodename":"Gaming","nodeid":"GA01"},{"nodename":"Mobile & Accessories","nodeid":"MO01"}]
</string>