Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Nested JSON Serialization

$
0
0

Dear all

I m using stored procedure/Vb.net

I have two related tables shown below.

Relational Tables - SQL Server

I need to create one JSON array for them in this format, 

{"IDCtry":1,"CtryName":"Germany": ["StateID":1,"StateName":"Duesseldorf"],"DCtry":2,"CtryName":"spain": ["StateID":1,"StateName":"Barcelona"],
}

I can already serialize one table using the following method

<WebMethod()> _<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=False)> _
    Public Function populateCtls(ByVal CtlName As String)
        Dim constr As String = ConfigurationManager.ConnectionStrings("ARTSQLConStrng").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("populateCtls", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@operator", SqlDbType.NVarChar).Value = CtlName
                cmd.Connection = con
                Dim ds As New DataSet()
                Using sda As New SqlDataAdapter(cmd)
                    sda.Fill(ds)
                End Using
                Dim jsondata As String = JsonConvert.SerializeObject(ds)
                Return jsondata
            End Using
        End Using
    End Function

but i cant figure out how to relate these records before serialization.

Shall I run two sql readers for two different select statements or is there a way to join them before I serialize the returned result,

currently I use stored procedures (PopulateCtls) which has my select statement.

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>