Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The structure you are looking for is a Dictionary of Lists that are created now. Try to deserialize your structure (the json string is corrected)</p> <pre><code>Dim serializer As New Web.Script.Serialization.JavaScriptSerializer() Dim target As String = "{'category':[{'id':'1','desc':'default'},{'id':'2','desc':'fun'}],'images':[{'imageID':'1','link':'images/logo.jpg','category':'1'},{'imageID':'2','link':'images/logo2.jpg','category':'2'}]}" Dim Desired = serializer.Deserialize(Of Object)(target) </code></pre> <p><code>Desired</code> is now the structure I need to create to get required JSON string. Now I create tables (They are in a DataSet and have names present in JSON) </p> <pre><code>Dim Ds As New DataSet For Each kvp As KeyValuePair(Of String, Object) In Desired Dim tbl As New DataTable(kvp.Key) Ds.Tables.Add(tbl) For Each drow As Dictionary(Of String, Object) In kvp.Value If tbl.Rows.Count = 0 Then For Each Name As String In drow.Keys tbl.Columns.Add(Name, GetType(Object)) Next End If Dim tblRow As DataRow = tbl.NewRow For Each fld As KeyValuePair(Of String, Object) In drow tblRow(fld.Key) = fld.Value Next tbl.Rows.Add(tblRow) Next Next </code></pre> <p>So far it I was just preparing data. Following is the desired answer. </p> <p>Now I create the structure and serialize it.</p> <pre><code>Dim Result As New Dictionary(Of String, Object) For Each tbl As DataTable In Ds.Tables Result.Add(tbl.TableName, GetRows(tbl)) Next Dim serialized As String = serializer.Serialize(Result) </code></pre> <p><code>GetRows</code> is modified from <code>GetJson</code></p> <pre><code>Public Function GetRows(ByVal dt As DataTable) As List(Of Dictionary(Of String, Object)) Dim rows As New List(Of Dictionary(Of String, Object)) Dim row As Dictionary(Of String, Object) For Each dr As DataRow In dt.Rows row = New Dictionary(Of String, Object) For Each col As DataColumn In dt.Columns row.Add(col.ColumnName, dr(col)) Next rows.Add(row) Next Return rows End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload