asp将数组for循环输出json格式 | 熊阿哥博客

asp将数组for循环输出json格式

ASP   2025-02-26 16:20   65   0  
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.ContentType = "application/json"
 
' 创建模拟数据数组 
Dim cities(2)
cities(0) = Array(1, "北京", "首都")
cities(1) = Array(2, "合肥", "省会")
cities(2) = Array(3, "重庆", "直辖市")
 
Dim jsonStr, i 
jsonStr = "["
 
For i = 0 To UBound(cities)
    jsonStr = jsonStr & "{"
    jsonStr = jsonStr & """id"":" & cities(i)(0) & ","
    jsonStr = jsonStr & """title"":""" & Server.HTMLEncode(cities(i)(1)) & ""","
    jsonStr = jsonStr & """caption"":""" & Server.HTMLEncode(cities(i)(2)) & """"
    jsonStr = jsonStr & "}"
    
    If i < UBound(cities) Then 
        jsonStr = jsonStr & ","
    End If 
Next 
 
jsonStr = jsonStr & "]"
 
Response.Write jsonStr 
%>


博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。