aspjosn 是一款 实现 VBScript代码JSON 序列化的ASP技术。
aspjosn 输入可以是对象或者数组类型。jsObject 和 jsArray 类在服务器端将数据转换成JSON,这两个类都基于 jsCore 实现。
aspjson 支持嵌套使用,例如,jsObject 方法可以包含数字、字符串、NULL、数组和其他原始类型,jsArray 方法可以包含这些 jsObject 方法,或者其他所有的原始类型。
ASP代码
<!--#include file="JSON_latest.asp"--> <% Dim member Set member = jsObject() member("name") = "Tuğrul" member("surname") = "Topuz" member("message") = "Hello World" member.Flush %>
输出
{"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
ASP代码
<!--#include file="JSON_latest.asp"--> <!--#include file="JSON_UTIL_latest.asp"--> <% QueryToJSON(dbconn, "SELECT name, surname FROM members WHERE age < 30").Flush %>
输出
[ { "name":"ali", "surname":"osman" }, { "name":"mahmut", "surname":"\u00E7\u0131nar" } ]
代码
<!--#include file="JSON_latest.asp"--> <% Dim a(1,1) a(0,0) = "zero - zero" a(0,1) = "zero - one" a(1,0) = "one - zero" a(1,1) = "one - one" Response.Write toJSON(a) %>
输出
[["zero - zero","zero - one"],["one - zero","one - one"]]
以下是 aspjson 2.0.4的源代码,使用时将下面代码复制保存成一个asp文件,然后在使用的代码中 include 包含就可以用了。当然,也建议到 googlecode 直接下载源文件,地址:https://code.google.com/p/aspjson/。
<% ' ' VBS JSON 2.0.3 ' Copyright (c) 2009 Tu餽ul Topuz ' Under the MIT (MIT-LICENSE.txt) license. ' Const JSON_OBJECT = 0 Const JSON_ARRAY = 1 Class jsCore Public Collection Public Count Public QuotedVars Public Kind ' 0 = object, 1 = array Private Sub Class_Initialize Set Collection = CreateObject("Scripting.Dictionary") 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 ' - 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) <> "jsCore" Then Err.Raise &hD, "class: class", "Incompatible types: '" & 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 Function jsEncode(str) Dim charmap(127), haystack() charmap(8) = "\b" charmap(9) = "\t" charmap(10) = "\n" charmap(12) = "\f" charmap(13) = "\r" charmap(34) = "\""" charmap(47) = "\/" charmap(92) = "\\" Dim strlen : strlen = Len(str) - 1 ReDim haystack(strlen) Dim i, charcode For i = 0 To strlen haystack(i) = Mid(str, i + 1, 1) charcode = AscW(haystack(i)) And 65535 If charcode < 127 Then If Not IsEmpty(charmap(charcode)) Then haystack(i) = charmap(charcode) ElseIf charcode < 32 Then haystack(i) = "\u" & Right("000" & Hex(charcode), 4) End If Else haystack(i) = "\u" & Right("000" & Hex(charcode), 4) End If Next jsEncode = Join(haystack, "") End Function ' converting Public Function toJSON(vPair) Select Case VarType(vPair) Case 0 ' Empty toJSON = "null" Case 1 ' Null toJSON = "null" Case 7 ' Date ' toJSON = "new Date(" & (vPair - CDate(25569)) * 86400000 & ")" ' let in only utc time 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 toJSON = RenderArray(vPair, 1, "") Case Else toJSON = Replace(vPair, ",", ".") End select End Function Function RenderArray(arr, depth, parent) Dim first : first = LBound(arr, depth) Dim last : last = UBound(arr, depth) Dim index, rendered Dim limiter : limiter = "," RenderArray = "[" For index = first To last If index = last Then limiter = "" End If On Error Resume Next rendered = RenderArray(arr, depth + 1, parent & index & "," ) If Err = 9 Then On Error GoTo 0 RenderArray = RenderArray & toJSON(Eval("arr(" & parent & index & ")")) & limiter Else RenderArray = RenderArray & rendered & "" & limiter End If Next RenderArray = RenderArray & "]" End Function Public Property Get jsString jsString = toJSON(Me) End Property Sub Flush If TypeName(Response) <> "Empty" Then Response.Write(jsString) ElseIf WScript <> Empty Then WScript.Echo(jsString) End If End Sub Public Function Clone Set Clone = ColClone(Me) End Function Private Function ColClone(core) Dim jsc, i Set jsc = new jsCore 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 End Class Function jsObject Set jsObject = new jsCore jsObject.Kind = JSON_OBJECT End Function Function jsArray Set jsArray = new jsCore jsArray.Kind = JSON_ARRAY End Function Function toJSON(val) toJSON = (new jsCore).toJSON(val) End Function %>
更多aspjson的功能,请参考起wifi页面: html" target="_blank">https://code.google.com/p/aspjson/w/list。
JSON 数据格式 JSON 是 JavaScript Object Notation 的简称,是一种轻量的数据表示方法。json格式采用key:value的方式记录数据,非常直观,比XML简洁,因而大受欢迎 介绍json格式前,先让我们看看XML格式。显然,XML 得到了相当多的关注(正面和负面的评价都有),已经在 Ajax 应用程序中广泛使用: <request> <firstName>
数据结构要在网络中传输或保存到文件,就必须对其编码和解码;目前存在很多编码格式:JSON,XML,gob,Google 缓冲协议等等。Go 语言支持所有这些编码格式;在后面的章节,我们将讨论前三种格式。 结构可能包含二进制数据,如果将其作为文本打印,那么可读性是很差的。另外结构内部可能包含匿名字段,而不清楚数据的用意。 通过把数据转换成纯文本,使用命名的字段来标注,让其具有可读性。这样的数据格式可
Excel转KML 在“数据处理”菜单栏中,点击“Excel转KML”,弹出对话框,点击打开XLS,选择要转换的Excel文件(可以添加LSV文件夹下示例数据中的EXCEL2KML示例数据.xls进行测试),读取完成后,可以在上方的表格里看到Excel里的信息。在Excel表格内容的下面分了两块,左侧一块为经纬度和气泡内容的选择,右侧一块是对要生成的kml图层的风格的设置。
上边格式如何转换为以下格式
本文向大家介绍ASP VBScrip读取JSON格式数据,包括了ASP VBScrip读取JSON格式数据的使用技巧和注意事项,需要的朋友参考一下 ASP代码读取JSON个数数据需要一个 json2.js 脚本,文件地址:https://raw.github.com/douglascrockford/JSON-js/master/json2.js。 下载 json2.js 文件,保存在自己的服务器
本文向大家介绍对json数据格式的理解?相关面试题,主要包含被问及对json数据格式的理解?时的应答技巧和注意事项,需要的朋友参考一下 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,json数据格式固定,可以被多种语言用作数据的传递。 PHP中处理json格式的函数为json_decode( string $json [, bool $assoc ]