0
我已經創建了一個函數,本質上使我能夠輸出任何我需要從我的數據庫中以類似於Facebook的FQL查詢方法作爲JSON的方法文本結果。Server.htmlDecode()從數據庫返回一個JSON字符串與vb.net遇到問題
我也可以使用相同的函數來獲取輸出作爲字典或(字典)的列表與VB功能用於其他目的。
Public Shared Function getDataList(sql As String, output As String, useDb As String, labelName As String, fileName As String)
Dim dataDetail
'' This function will return the content of a query as either a key/value dictionary, or a key(key/value) result for formating
'' as JSON for JS handling or a Dictionary to use with server side codes
If labelName <> "" Then
dataDetail = New List(Of Generic.Dictionary(Of String, String))
Else
dataDetail = New Generic.Dictionary(Of String, Generic.Dictionary(Of String, String))
End If
Dim connection As OdbcConnection = Common.getConnection(useDb)
Try
connection.Open()
Dim connect As OdbcCommand = Common.createCommand(sql, connection, useDb)
Dim getData As New DataTable()
getData.Load(connect.ExecuteReader(CommandBehavior.CloseConnection))
For Each row In getData.Rows
Dim rowDetail As New Generic.Dictionary(Of String, String)
For Each column In getData.Columns
Dim theData = row(column)
If IsDBNull(theData) Then
theData = ""
End If
If LCase(output) = "json" Then
theData = HttpContext.Current.Server.HtmlDecode(theData)
End If
rowDetail.Add(column.ToString, theData)
Next
Next
connection.Close()
Catch theError As Exception
HttpContext.Current.Response.Write(theError)
Finally
connection.Dispose()
End Try
If output = "json" Then
Dim serializer As New JavaScriptSerializer
HttpContext.Current.Response.Write(serializer.Serialize(dataDetail))
ElseIf output = "dictionary" Then
Return dataDetail
End If
End Function
這工作正常,我發現它非常有用,可以快速獲取數據庫中的數據。
我唯一的問題是,當我得到輸出爲JSON文件時,我想要將任何存儲在數據庫中的數據作爲編碼HTML進行轉換,以便在瀏覽器中很好地顯示。
線
theData = HttpContext.Current.Server.HtmlDecode(theData)
是爲了做到這一點,確實有點... ...但今天這個人物:
'
是不是解碼。
有什麼想法?