目前我正在使用json.net将数据集序列化为json。
VB.NET
<WebMethod()>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Sub GetData()
Dim json As String
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("Con").ConnectionString)
Using cmd As New SqlCommand("sp", con)
cmd.CommandType = CommandType.StoredProcedure
Using sda As New SqlDataAdapter(cmd)
Using ds As New DataSet()
sda.Fill(ds)
json = JsonConvert.SerializeObject(ds, Formatting.Indented)
End Using
End Using
End Using
End Using
Context.Response.ContentType = "application/json; charset=utf-8"
Context.Response.Write(json)
End Sub
JSON (输出)
{
"Table": [
{
"Name": "Head1",
"Number": 0
},
{
"Name": "Head1",
"Number": 1
},
{
"Name": "Head2",
"Number": 0
}
]
}
我创建了一个单独的存储过程来填充嵌套数据,并试图找出如何遍历数据集/ json的行并将嵌套数据插入到每个项目中。
在.net中我只会做一个for each
项循环。
JSON
{
"Table": [
{
"Name": "Head1"
"NumberSection": [
"Number": 0,
"Number": 1
]
},
{
"Name": "Head2"
"NumberSection": [
"Number": 0
]
}
]
}
建议可以在C#
或VB