I'm new to web API, and all the examples are in C# which doesn't help, as such I've hit a roadblock early on. I'm returning data from SQL, putting it an object array list, and then trying to return it so it could be read by a JSON client.
This is my default GET on my controller:
Function Index() As IEnumerable(Of String)
Dim Sites As New ArrayList
Dim dt As DataTable = DataLayer.ExecuteNoParamStoredProcedure("stored_proc", "connection_string")
For Each r As DataRow In dt.Rows()
Sites.Add(New SiteDetails(r("SiteName"),r("SiteId")))
Next
Return Sites
End Function
And here is my SiteDetails class:
Public Class SiteDetails
Public site As String
Public siteid As String
Public Sub New(sitename As String, id As String)
site = sitename
siteid = id
End Sub
End Class
Questions: How to I make it output the data on the page in a format that isn't either an error or just the object name? Is there a better way to do what I'm doing?
Joe
EDIT just to comment, the above doesn't work from the off, because it can't the return type (IEnumerable(Of String)) doesn't allow an arraylist to be returned, this is the bulk of my issue.
ArrayList
. This is still there only for backwards compatibility to old code. Use strongly-typedList (Of T)
instead – T.S. Oct 27 '16 at 16:19