I have the following code which serialize an array to json:
Dim col1 As New ArrayList
Dim col2 As New ArrayList
objJSONStringBuilder = New StringBuilder()
objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))
objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection)
objSQLCommand.Connection.Open()
objSQLDataReader = objSQLCommand.ExecuteReader()
While objSQLDataReader.Read()
col1.Add(objSQLDataReader("col1"))
End While
objSQLDataReader.Close()
objSQLCommand.Connection.Close()
Dim serializer As New JavaScriptSerializer()
Dim arrayJson As String = serializer.Serialize(col1)
Return arrayJson
which returns
[
"dept1",
"dept2",
"dept3",
"dept4",
"dept5",
"dept6"
]
How do I get it to return this instead?
the second array col2 on it’s own would return:
[
{"department_name":"dept1"},
{"department_name":"dept2"},
{"department_name":"dept3"},
{"department_name":"dept4"},
{"department_name":"dept5"},
{"department_name":"dept6"}
]
try something like this: