This article mainly introduces the relevant information on the method of using asp to read and output json code from the database. Friends who need it can refer to it.
Copy the code code as follows:Function GetTable(Table,Where,Order,OrderSort,curpage, pagesize,MiniJson)
'Author : nigou
'Usage: Response.Write GetTable (Table table name, Where condition, Order primary key (required), OrderSort (asc, desc), curpage current page, pagesize number of items per page, whether MiniJson is output in miniUI format)
'
dimi,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: The last parameter is developed for miniUI and can be ignored.
The above is the entire content of this article, I hope you all like it.