ASP JSON类源码分享

复制代码 代码如下:

<%

'============================================================

' 文件名称 : /Cls_Json.asp

' 文件作用 : 系统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

' 设置对象类型

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

%>

时间: 2024-09-21 09:43:51

ASP JSON类源码分享的相关文章

android微信支付源码分享_Android

本文为大家分享了android微信支付源码,供大家参考,具体内容如下 参数配置 public static final String APP_ID ; /** 在微信开放平台注册app,微信给分配的id **/ public static final String MCH_ID; /** 申请开通微信支付,成功后微信会给你发一封邮件,给你分配一个商户平台账号,在资料里有商户ID **/ public static final String API_KEY; /** 在微信发给你的那封邮件里,给你

asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证

原文:asp.net mvc源码分析-DefaultModelBinder 自定义的普通数据类型的绑定和验证 在前面的文章中我们曾经涉及到ControllerActionInvoker类GetParameterValue方法中有这么一句代码:    ModelBindingContext bindingContext = new ModelBindingContext() {                 FallbackToEmptyPrefix = (parameterDescriptor

基于jquery步骤进度条源码分享_jquery

基于jQuery网页步骤流程进度条代码里面包含两款不同效果的jQuery步骤进度条特效.效果图如下: 在线预览       源码下载 html代码: <div class="step_context test"></div> 当前步骤: 第<input type="text" value="5" id="currentStepVal" />步 <button onclick="

Android 用Time和Calendar获取系统当前时间源码分享(年月日时分秒周几)

概述 用Time和Calendar获取系统当前时间(年月日时分秒周几) 效果图 源码: import android.app.Activity; import android.os.Bundle; import android.text.format.Time; import android.view.View; import android.widget.RelativeLayout; import android.widget.TextView; import java.util.Calen

ASP求平均分源码示例

用ASP求平均分源码 <%dim fs(4),i,out_nfs(0)=85fs(1)=80fs(2)=75fs(3)=70fs(4)=65for i=0 to (ubound(fs))  out_n=out_n+fs(i)nextout_n = out_n/(ubound(fs)+1)response.write "平均分为:"&"    "&out_n%>

ASP调用存储过程源码示例

ASP调用存储过程源码示例 以下是代码:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <%     Set conn = CreateObject("ADODB.Connection")     strCon = "Provider=SQLNCLI;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Nor

本人自用的global.js库源码分享

 这篇文章主要介绍了本人自用的global.js库源码分享,源码中包含常用WEB操作,如命名空间.DOM操作.数据判断.Cookie操作等功能,需要的朋友可以参考下     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

asp net 问题 源码-打开一个ASP.NET的源码这样报错,请教了

问题描述 打开一个ASP.NET的源码这样报错,请教了 今天在CSDN下载了某个同学的ASP.NET+ SQLSERVER 源码,结果打开报这样的错误 Microsoft Visual Studio 無法讀取專案檔 'ConferenceRoomsBook.csproj'.E:ConferenceRoomsBookConferenceRoomsBook.csproj(343,11): The imported project "C:Program Files (x86)MSBuildMicros

仿乐享微信php源码分享,微信订房订餐系统

99%的人不知道的微信秘密!微信里的商机.仿乐享微信源码分享,把你的生意做到微信里. WeiKuCMS (微酷CMS)功能特点:粉丝行为分析,人工客服,二维码折扣,微菜 单,微统计,会员卡签到,微会员,刮刮卡,大转盘,优惠券,积分兑换,微官网,砸金蛋,微调研,微投票,微相册,微商城,微团购,微留言,微喜帖,商家入 驻,微门店,微餐饮,微酒店,微教育,微物业,微医疗,微信墙,微花店,微美容,微生活. 微信公共账号轻松接入,无限自定义图文回复. 微酷WeiKuCMS,让微信营销如此简单!微酷WeiK