本文目录一览:
用asp怎么将查询结果转化为json
你说的是ASP VBS吗?
我这里有一个json编码函数
'Json编码 by Shirne
'支持数组,Dictionary,Recordset等对象直接编码,支持数组中 key":"value格式
Function JsonEncode(json)
Dim i, l, key, str
str = ""
If IsArray(json) Then
l = UBound(json)
If TypeName(json(0))="String" Then
If InStr(json(0),":")0 Then
str = str "{"
For i=0 To l
str = str """" Left(json(i),InStr(json(i),":")-1) """:"
str = str """" EncodeJSON(Mid(json(i),InStr(json(i),":")+1)) """"
If il Then str = str ","
Next
str = str "}"
JsonEncode = str
Exit Function
End If
End If
str = str "["
For i=0 To l
str = str JsonEncode(json(i))
If il Then str = str ","
Next
str = str "]"
ElseIf TypeName(json)="Dictionary" Then
l = json.Count
i = 0
str = str "{"
For Each key In json
i = i + 1
str = str """" key """:"
str = str JsonEncode(json(key))
If il Then str = str ","
Next
str = str "}"
ElseIf TypeName(json)="Recordset" Then
Dim Field
l = json.Fields.Count
str = str "["
Do Until json.EOF
i = 0
str = str "{"
For Each Field In json.Fields
i = i + 1
str = str """" LCase(Field.Name) """:"
'If UCase(Field.Name)="IP" Then
' str = str JsonEncode(IPMask(Field.Value))
'Else
str = str JsonEncode(Field.Value)
'End If
If il Then str = str ","
Next
str = str "}"
json.MoveNext
If Not json.EOF Then str = str ","
Loop
str = str "]"
Else
Select Case VarType(json)
Case 2,3,4,5,6
str = str json
Case Else
str = str """" EncodeJSON(json"") """"
End Select
End If
JsonEncode = str
End Function
用法:
Response.Write JsonEncode(Array("state:"stat, "message:"msg, "url:"param))
//或
Response.Write JsonEncode(dictionaryObject)
asp.net 生成json文件
json有自己的格式,你就按照这个格式写出字符串 然后response出去个文件流 名字是xx.json就可以
ASP怎样生成json格式?
{
"box": {
"name": "%=name%", '读取数据库记录里的name值
"value":%=value%"' 读取数据库记录里的value值
}
读到数据后输出到页面里就好了