この記事では、asp を使用してデータベースから json コードを読み取って出力する方法に関する関連情報を主に紹介します。必要な友人は参照してください。
次のようにコードをコピーします。関数 GetTable(Table,Where,Order,OrderSort,curpage,pagesize,MiniJson)
作者:にごう
'使用法: Response.Write GetTable (テーブルテーブル名、Where 条件、Order 主キー (必須)、OrderSort (asc、desc)、curpage 現在のページ、pagesize ページごとのアイテム数、MiniJson が miniUI 形式で出力されるかどうか)
'
ディミ、j、rs
OrderSort= の場合 OrderSort=asc
if Where= then Where=asc
Set Rs=Server.CreateObject(adodb.recordset)
curpage>1 の場合
TmpSql=select a.* from ( select top & (curpage) * pagesize & * from & Table & where & where & order by & Order & & OrderSort & ) 左結合 ( 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分
それ以外
TmpSql=select a.* from ( select top & (curpage) * pagesize & * from & Table & where & where & order by & Order & & OrderSort & ) a
終了する場合
if pagesize=0 then TmpSql = select * from & Table
Rs.open TmpSql,conn,1,1
RealSize=Rs.レコード数
i=0 から Rs.recordcount-1 の場合
TmpJson= TmpJson & {
j=0 から Rs.fields.count-1 の場合
TmpJson= TmpJson & &(Rs.fields(j).name) & :
TmpJson= TmpJson & & Rs(j) &
j<Rs.fields.count-1 の場合、 TmpJson= TmpJson & 、
次
TmpJson= TmpJson & }
if i<Rs.recordcount-1 then TmpJson= TmpJson & ,
TmpJson= TmpJson & vbcrlf
rs.movenext
次
閉じる
MiniJson=1 の場合
CountSql=select count(& order &) from & Table & where & where
Rs.open CountSql,Conn,1,1
カウント=Rs(0)
Rs.Close
GetTable=ToMiniUi(TmpJson,Counts)
それ以外
GetTable=toJson(TmpJson)
終了する場合
Rs=何も設定しない
終了機能
関数 toJson(JsonStr)
toJson=[ & vbcrlf & JsonStr & vbcrlf & ]
終了関数
関数 ToMiniUi(JsonStr,total)
ToMiniUI={
ToMiniUI=ToMiniUI & total: & total & , & vbcrlf
ToMiniUI=ToMiniUI & データ: [ & JsonStr
ToMiniUI=ToMiniUI & ]}
終了機能
PS: 最後のパラメータは miniUI 用に開発されたものであり、無視できます。
以上がこの記事の全内容です。皆さんに気に入っていただければ幸いです。