ASP implementation read database output JSON code

Source: Internet
Author: User
Tags json table name tojson

The code is as follows:


Function gettable (Table,where,order,ordersort,curpage, Pagesize,minijson)
' Author:nigou
' Use method: Response.Write gettable (table name, where condition, order primary key (required), Ordersort (ASC,DESC), curpage current page, pagesize per page number, Minijson is output as MINIUI format)
'
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: The last parameter is developed for MINIUI, can ignore

The above is the entire content of this article, I hope you can enjoy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.