<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% ' 定义JSON数据字符串 Dim jsonData jsonData = "[{""id"":1,""title"":""北京"",""caption"":""shouduo""},{""id"":2,""title"":""合肥"",""caption"":""省会""},{""id"":3,""title"":""重庆"",""caption"":""直辖市""}]" ' 创建一个JSON对象来处理数据 Set oJSON = Server.CreateObject("Scripting.Dictionary") oJSON.CompareMode = 1 '设置比较模式,不区分大小写 ' 将JSON字符串解析为可操作的数据结构(这里简单模拟,实际可能需要更复杂的解析) Dim jsonArray jsonArray = array() jsonArray = split(jsonData, "},{") ' 构建输出的JSON数组结构 Response.Write "[" For i = 0 To UBound(jsonArray) Dim itemData itemData = jsonArray(i) If i = 0 Then itemData = Mid(itemData, 2) '去掉第一个元素开头的 [ End If If i = UBound(jsonArray) Then itemData = Left(itemData, Len(itemData) - 2) '去掉最后一个元素结尾的 ] End If Dim id, title, caption id = GetValueFromJSON(itemData, "id") title = GetValueFromJSON(itemData, """title""") caption = GetValueFromJSON(itemData, """caption""") Response.Write "{" Response.Write """id"": """ & id & """," Response.Write """title"": """ & title & """," Response.Write """caption"": """ & caption & """" Response.Write "}" If i < UBound(jsonArray) Then Response.Write "," End If Next Response.Write "]" ' 辅助函数:从JSON字符串中提取指定键的值 Function GetValueFromJSON(jsonStr, key) Dim startIndex, endIndex startIndex = InStr(jsonStr, key) + Len(key) + 2 endIndex = InStr(startIndex, jsonStr, """") - 1 GetValueFromJSON = Mid(jsonStr, startIndex, endIndex - startIndex + 1) End Function Set oJSON = Nothing %>