复制代码 代码如下:
Function GetTable(Table,Where,Order,OrderSort,curpage, pagesize,MiniJson)
'Author : nigou
'使用方法 : Response.Write 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=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:最后的参数是针对miniUI开发的,可以无视

以上就是本文的全部内容了,希望大家能够喜欢。

标签:
asp,读取数据库,输出json

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“asp实现读取数据库输出json代码”

暂无“asp实现读取数据库输出json代码”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。