admin 管理员组文章数量: 1086019
2024年3月29日发(作者:html是一种web编程语言)
代码如下:
Function GetTable(Table,Where,Order,OrderSort,curpage, pagesize,MiniJson)
'Author : nigou
'使用方法 : GetTable(Table表名,Where条件,Order主键(必
须),OrderSort(asc,desc),curpage当前页, pagesize每页条数,MiniJson是否输出为
miniUI格式)
'
dim i, j ,rs
if OrderSort="" Then OrderSort="asc"
if Where="" Then Where="asc"
Set Rs=Object("set")
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
TmpSql,conn,1,1
RealSize=count
for i=0 to count-1
TmpJson= TmpJson & "{"
for j=0 to -1
TmpJson= TmpJson & """" &((j).name) & """ : "
TmpJson= TmpJson & """" & Rs(j) & """"
if j<-1 then TmpJson= TmpJson & " , "
next
TmpJson= TmpJson & " }"
if i<count-1 then TmpJson= TmpJson & ","
TmpJson= TmpJson & vbcrlf
xt
next
if MiniJson=1 Then
CountSql="select count("& order &") from " & Table & "
where " & where
CountSql,Conn,1,1
Counts=Rs(0)
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:最后的参数是针对miniUI开发的,可以无视
以上就是本文的全部内容了,希望大家能够喜欢。
更多信息请查看IT技术专栏
版权声明:本文标题:asp实现读取数据库输出json代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1711704527a606537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论