佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > ASP JSON類源碼分享

ASP JSON類源碼分享

熱門標(biāo)簽:阿里云 團(tuán)購網(wǎng)站 銀行業(yè)務(wù) 科大訊飛語音識別系統(tǒng) Mysql連接數(shù)設(shè)置 電子圍欄 Linux服務(wù)器 服務(wù)器配置
復(fù)制代碼 代碼如下:

%
'============================================================
' 文件名稱 : /Cls_Json.asp
' 文件作用 : 系統(tǒng)JSON類文件
' 文件版本 : VBS JSON(JavaScript Object Notation) Version 2.0.2
' 程序修改 : Cloud.L
' 最后更新 : 2009-05-12
'============================================================
' 程序核心 : JSON官方 http://www.json.org/
' 作者博客 : Http://www.cnode.cn
'============================================================
Class Json_Cls

Public Collection
Public Count
Public QuotedVars '是否為變量增加引號
Public Kind ' 0 = object, 1 = array

Private Sub Class_Initialize
Set Collection = Server.CreateObject(GP_ScriptingDictionary)
QuotedVars = True
Count = 0
End Sub

Private Sub Class_Terminate
Set Collection = Nothing
End Sub

' counter
Private Property Get Counter
Counter = Count
Count = Count + 1
End Property

' 設(shè)置對象類型
Public Property Let SetKind(ByVal fpKind)
Select Case LCase(fpKind)
Case "object":Kind=0
Case "array":Kind=1
End Select
End Property

' - data maluplation
' -- pair
Public Property Let Pair(p, v)
If IsNull(p) Then p = Counter
Collection(p) = v
End Property

Public Property Set Pair(p, v)
If IsNull(p) Then p = Counter
If TypeName(v) > "Json_Cls" Then
Err.Raise hD, "class: class", "class object: '" TypeName(v) "'"
End If
Set Collection(p) = v
End Property

Public Default Property Get Pair(p)
If IsNull(p) Then p = Count - 1
If IsObject(Collection(p)) Then
Set Pair = Collection(p)
Else
Pair = Collection(p)
End If
End Property
' -- pair
Public Sub Clean
Collection.RemoveAll
End Sub

Public Sub Remove(vProp)
Collection.Remove vProp
End Sub
' data maluplation

' encoding
Public Function jsEncode(str)
Dim i, j, aL1, aL2, c, p

aL1 = Array(h22, h5C, h2F, h08, h0C, h0A, h0D, h09)
aL2 = Array(h22, h5C, h2F, h62, h66, h6E, h72, h74)
For i = 1 To Len(str)
p = True
c = Mid(str, i, 1)
For j = 0 To 7
If c = Chr(aL1(j)) Then
jsEncode = jsEncode "\" Chr(aL2(j))
p = False
Exit For
End If
Next

If p Then
Dim a
a = AscW(c)
If a > 31 And a 127 Then
jsEncode = jsEncode c
ElseIf a > -1 Or a 65535 Then
jsEncode = jsEncode "\u" String(4 - Len(Hex(a)), "0") Hex(a)
End If
End If
Next
End Function

' converting
Public Function toJSON(vPair)
Select Case VarType(vPair)
Case 1 ' Null
toJSON = "null"
Case 7 ' Date
' yaz saati problemi var
' jsValue = "new Date(" Round((vVal - #01/01/1970 02:00#) * 86400000) ")"
toJSON = """" CStr(vPair) """"
Case 8 ' String
toJSON = """" jsEncode(vPair) """"
Case 9 ' Object
Dim bFI,i
bFI = True
If vPair.Kind Then toJSON = toJSON "[" Else toJSON = toJSON "{"
For Each i In vPair.Collection
If bFI Then bFI = False Else toJSON = toJSON ","

If vPair.Kind Then
toJSON = toJSON toJSON(vPair(i))
Else
If QuotedVars Then
toJSON = toJSON """" i """:" toJSON(vPair(i))
Else
toJSON = toJSON i ":" toJSON(vPair(i))
End If
End If
Next
If vPair.Kind Then toJSON = toJSON "]" Else toJSON = toJSON "}"
Case 11
If vPair Then toJSON = "true" Else toJSON = "false"
Case 12, 8192, 8204
Dim sEB
toJSON = MultiArray(vPair, 1, "", sEB)
Case Else
toJSON = Replace(vPair, ",", ".")
End select
End Function

Public Function MultiArray(aBD, iBC, sPS, ByRef sPT) ' Array BoDy, Integer BaseCount, String PoSition
Dim iDU, iDL, i ' Integer DimensionUBound, Integer DimensionLBound
On Error Resume Next
iDL = LBound(aBD, iBC)
iDU = UBound(aBD, iBC)

Dim sPB1, sPB2 ' String PointBuffer1, String PointBuffer2
If Err = 9 Then
sPB1 = sPT sPS
For i = 1 To Len(sPB1)
If i > 1 Then sPB2 = sPB2 ","
sPB2 = sPB2 Mid(sPB1, i, 1)
Next
MultiArray = MultiArray toJSON(Eval("aBD(" sPB2 ")"))
Else
sPT = sPT sPS
MultiArray = MultiArray "["
For i = iDL To iDU
MultiArray = MultiArray MultiArray(aBD, iBC + 1, i, sPT)
If i iDU Then MultiArray = MultiArray ","
Next
MultiArray = MultiArray "]"
sPT = Left(sPT, iBC - 2)
End If
End Function

Public Property Get ToString
ToString = toJSON(Me)
End Property

Public Sub Flush
If TypeName(Response) > "Empty" Then
Response.Write(ToString)
ElseIf WScript > Empty Then
WScript.Echo(ToString)
End If
End Sub

Public Function Clone
Set Clone = ColClone(Me)
End Function

Private Function ColClone(core)
Dim jsc, i
Set jsc = New Json_Cls
jsc.Kind = core.Kind
For Each i In core.Collection
If IsObject(core(i)) Then
Set jsc(i) = ColClone(core(i))
Else
jsc(i) = core(i)
End If
Next
Set ColClone = jsc
End Function

Public Function QueryToJSON(dbc, sql)
Dim rs, jsa,col
Set rs = dbc.Execute(sql)
Set jsa = New Json_Cls
jsa.SetKind="array"
While Not (rs.EOF Or rs.BOF)
Set jsa(Null) = New Json_Cls
jsa(Null).SetKind="object"
For Each col In rs.Fields
jsa(Null)(col.Name) = col.Value
Next
rs.MoveNext
Wend
Set QueryToJSON = jsa
End Function

End Class
%>
您可能感興趣的文章:
  • ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp
  • asp實(shí)現(xiàn)讀取數(shù)據(jù)庫輸出json代碼
  • asp對復(fù)雜json的解析一定要注意要點(diǎn)
  • ASP JSON類文件的使用方法
  • asp下以Json獲取中國天氣網(wǎng)天氣的代碼
  • ASP Json Parser修正版
  • ASP 處理JSON數(shù)據(jù)的實(shí)現(xiàn)代碼

標(biāo)簽:蚌埠 大理 衢州 江蘇 萍鄉(xiāng) 廣元 衡水 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP JSON類源碼分享》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    灵山县| 东台市| 哈尔滨市| 临邑县| 贡山| 古丈县| 饶河县| 类乌齐县| 辉南县| 昌乐县| 昆山市| 苍南县| 北安市| 湛江市| 福泉市| 永胜县| 浦东新区| 清河县| 安吉县| 稻城县| 崇明县| 临颍县| 遵化市| 漳浦县| 平昌县| 三都| 海安县| 沛县| 连城县| 南平市| 陈巴尔虎旗| 江华| 即墨市| 合江县| 洪江市| 奎屯市| 龙口市| 当雄县| 东丽区| 滨海县| 富裕县|