asp将数据库读取的数据输出json格式
                    
                    
                                                    
                            ASP
                             
                                                
                        2025-02-26 16:20
                         
                        
                        653
                         
                        
                        0
                         
                    
                    
                                                
                            <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.ContentType = "application/json"
 
Dim conn, rs 
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "数据库连接字符串"
 
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT id, title, caption FROM cities", conn 
 
Dim jsonStr 
jsonStr = "["
 
Do While Not rs.EOF 
    jsonStr = jsonStr & "{"
    jsonStr = jsonStr & """id"":" & rs("id") & ","
    jsonStr = jsonStr & """title"":""" & Server.HTMLEncode(rs("title")) & ""","
    jsonStr = jsonStr & """caption"":""" & Server.HTMLEncode(rs("caption")) & """"
    jsonStr = jsonStr & "}"
    
    rs.MoveNext 
    If Not rs.EOF Then jsonStr = jsonStr & ","
Loop 
 
jsonStr = jsonStr & "]"
 
Response.Write jsonStr 
 
rs.Close 
Set rs = Nothing 
conn.Close 
Set conn = Nothing 
%>