ASP循环数组并输出JSON格式
ASP
2025-02-26 13:57
72
0
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
' 定义数据数组
Dim data
data = Array("{""id"": 1, ""title"": ""北京"", ""caption"": ""首都"" }","{""id"": 1, ""title"": ""北京"", ""caption"": ""首都"" }","{""id"": 1, ""title"": ""北京"", ""caption"": ""首都"" }")
' 构建JSON数组
Dim jsonArray
jsonArray = "["
For i = LBound(data) To UBound(data)
jsonArray = jsonArray & data(i)
If i < UBound(data) Then
jsonArray = jsonArray & ","
End If
Next
jsonArray = jsonArray & "]"
' 设置响应头为JSON格式
Response.ContentType = "application/json"
Response.Charset = "UTF-8"
' 输出JSON数据
Response.Write jsonArray
%>