asp實現(xiàn)讀取數(shù)據(jù)庫輸出json代碼
來源:易賢網(wǎng) 閱讀:877 次 日期:2015-03-13 13:31:45
溫馨提示:易賢網(wǎng)小編為您整理了“asp實現(xiàn)讀取數(shù)據(jù)庫輸出json代碼”,方便廣大網(wǎng)友查閱!

代碼如下:

Function GetTable(Table,Where,Order,OrderSort,curpage, pagesize,MiniJson)

'Author : nigou

'使用方法 : Response.Write GetTable(Table表名,Where條件,Order主鍵(必須),OrderSort(asc,desc),curpage當前頁, pagesize每頁條數(shù),MiniJson是否輸出為miniUI格式)

'

dim i, j ,rs

if OrderSort="" Then OrderSort="asc"

if Where="" Then Where="asc"

Set Rs=Server.CreateObject("adodb.recordset")

if curpage>1 then

TmpSql="select a.* from ( select top " & (curpage) * pagesize & " * from " & Table & " where " & where & " order by " & Order & " " & OrderSort & ") a left join ( select top " & (curpage-1) * pagesize & " * from " & Table & " where " & where & " order by " & Order & " " & OrderSort & ") b on a." & Order & "=b." & Order & " where iif(b." & Order & ",'0','1')='1'"

else

TmpSql="select a.* from ( select top " & (curpage) * pagesize & " * from " & Table & " where " & where & " order by " & Order & " " & OrderSort & ") a "

end if

if pagesize=0 Then TmpSql = "select * from " & Table

Rs.open TmpSql,conn,1,1

RealSize=Rs.recordcount

for i=0 to Rs.recordcount-1

TmpJson= TmpJson & "{"

for j=0 to Rs.fields.count-1

TmpJson= TmpJson & """" &(Rs.fields(j).name) & """ : "

TmpJson= TmpJson & """" & Rs(j) & """"

if j<Rs.fields.count-1 then TmpJson= TmpJson & " , "

next

TmpJson= TmpJson & " }"

if i<Rs.recordcount-1 then TmpJson= TmpJson & ","

TmpJson= TmpJson & vbcrlf

rs.movenext

next

Rs.close

if MiniJson=1 Then

CountSql="select count("& order &") from " & Table & " where " & where

Rs.open CountSql,Conn,1,1

Counts=Rs(0)

Rs.Close

GetTable=ToMiniUi(TmpJson,Counts)

Else

GetTable=toJson(TmpJson)

end if

Set Rs=nothing

End Function

function toJson(JsonStr)

toJson="[" & vbcrlf & JsonStr & vbcrlf & "]"

end function

Function ToMiniUi(JsonStr,total)

ToMiniUI="{"

ToMiniUI=ToMiniUI & """total"":"" " & total & """," & vbcrlf

ToMiniUI=ToMiniUI & """data"": [" & JsonStr

ToMiniUI=ToMiniUI & "]}"

End Function

PS:最后的參數(shù)是針對miniUI開發(fā)的,可以無視

以上就是本文的全部內(nèi)容了,希望大家能夠喜歡。

更多信息請查看IT技術專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機網(wǎng)站地址:asp實現(xiàn)讀取數(shù)據(jù)庫輸出json代碼

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)