aspJSON

2025-12-07 0 274

JSON object class 3.8.1

By RCDMK – rcdmk[at]hotmail[dot]com

Licence:

MIT license: http://ope*nso**urce.org/licenses/mit-license.php
The MIT License (MIT)
Copyright (c) 2016 RCDMK – rcdmk[at]hotmail[dot]com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \”Software\”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED \”AS IS\”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

How to use:

This lib requires LCID (Locale Code IDentifier) property of your ASP application before use.
You can do this by setting the LCID in one of the following ways:

  • On the page declaration at the top of the page to set it to the entire page (eg.: <%@ LCID=1046 %>), OR
  • On the Session object to set it to all pages in the entire session (eg.: Session.LCID = 1046), OR
  • On the Response object, before using the class, to set it beyond this point on the page (eg.: Response.LCID = 1046)
Response.LCID = 1046 \' REQUIRED! Set your LCID here (1046 = Brazilian). Could also be the LCID property of the page declaration or the Session.LCID property

\' instantiate the class
set JSON = New JSONobject

\' add properties
JSON.Add \"prop1\", \"someString\"
JSON.Add \"prop2\", 12.3
JSON.Add \"prop3\", Array(1, 2, \"three\")

\' remove properties
JSON.Remove \"prop2\"
JSON.Remove \"thisDoesNotExistsAndWillDoNothing\"

\' change some values
JSON.Change \"prop1\", \"someOtherString\"
JSON.Change \"prop4\", \"thisWillBeCreated\" \' this property doen\'t exists and will be created automagically

\' get the values
Response.Write JSON.Value(\"prop1\") & \"<br>\"
Response.Write JSON.Value(\"prop2\") & \"<br>\"
Response.Write JSON(\"prop3\").Serialize() & \"<br>\" \' default function is equivalent to `.Value(propName)` - this property returns a JSONarray object
Response.Write JSON(\"prop4\") & \"<br>\"

\' get the JSON formatted output
Dim jsonString
jsonString = JSON.Serialize() \' this will contain the string representation of the JSON object

JSON.Write() \' this will write the output to the Response - equivalent to: Response.Write JSON.Serialize()

\' load and parse some JSON formatted string
jsonString = \"[{ \"\"strings\"\" : \"\"valorTexto\"\", \"\"numbers\"\": 123.456, \"\"arrays\"\": [1, \"\"2\"\", 3.4, [5, 6, [7, 8]]], \"\"objects\"\": { \"\"prop1\"\": \"\"outroTexto\"\", \"\"prop2\"\": [ { \"\"id\"\": 1, \"\"name\"\": \"\"item1\"\" }, { \"\"id\"\": 2, \"\"name\"\": \"\"item2\"\", \"\"teste\"\": { \"\"maisum\"\": [1, 2, 3] } } ] } }]\" \' double double quotes here because of the VBScript quotes scaping

set oJSONoutput = JSON.Parse(jsonString) \' this method returns the parsed object. Arrays are parsed to JSONarray objects

JSON.Write() 		\' outputs: \'{\"data\":[{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]],\"objects\":{\"prop1\":\"outroTexto\",\"prop2\":[{\"id\":1,\"name\":\"item1\"},{\"id\":2,\"name\":\"item2\",\"teste\":{\"maisum\":[1,2,3]}}]}}]}\'
oJSONoutput.Write() \' outputs: \'[{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]],\"objects\":{\"prop1\":\"outroTexto\",\"prop2\":[{\"id\":1,\"name\":\"item1\"},{\"id\":2,\"name\":\"item2\",\"teste\":{\"maisum\":[1,2,3]}}]}}]\'

\' if the string represents an object (not an array of objects), the current object is returned so there is no need to set the return to a new variable
jsonString = \"{ \"\"strings\"\" : \"\"valorTexto\"\", \"\"numbers\"\": 123.456, \"\"arrays\"\": [1, \"\"2\"\", 3.4, [5, 6, [7, 8]]] }\"

JSON.Parse(jsonString)
JSON.Write() \' outputs: \'{\"strings\":\"valorTexto\",\"numbers\":123.456,\"arrays\":[1,\"2\",3.4,[5,6,[7,8]]]}\'

To load records from a database:

\' load records from an ADODB.Recordset
dim cn, rs
set cn = CreateObject(\"ADODB.Connection\")
cn.Open \"yourConnectionStringGoesHere\"

set rs = cn.execute(\"SELECT id, nome, valor FROM pedidos ORDER BY id ASC\")
\' this could also be:
\' set rs = CreateObject(\"ADODB.Recordset\")
\' rs.Open \"SELECT id, nome, valor FROM pedidos ORDER BY id ASC\", cn	

JSON.LoadRecordset rs
JSONarr.LoadRecordset rs

rs.Close
cn.Close
set rs = Nothing
set cn = Nothing

JSON.Write() 		\' outputs: {\"data\":[{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]}
JSONarr.Write() 	\' outputs: [{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]

To change the default property name (\”data\”) when loading arrays and recordsets, use the defaultPropertyName property:

JSON.defaultPropertyName = \"CustomName\"
JSON.Write() 		\' outputs: {\"CustomName\":[{\"id\":1,\"nome\":\"nome 1\",\"valor\":10.99},{\"id\":2,\"nome\":\"nome 2\",\"valor\":19.1}]}

If you want to use arrays, I have something for you too

\' instantiate the class
set JSONarr = New JSONarray

\' add something to the array
JSONarr.Push JSON 	\' Can be JSON objects, and even JSON arrays
JSONarr.Push 1.25 	\' Can be numbers
JSONarr.Push \"and strings too\"

\' write to page
JSONarr.Write() \' Guess what? This does the same as the Write method from JSON object

To loop arrays you have to access the items property of the JSONarray object and you can also access the items trough its index:

dim i, item


\' more readable loop
for each item in JSONarr.items
	if isObject(item) and typeName(item) = \"JSONobject\" then
		item.write()
	else
		response.write item
	end if
	
	response.write \"<br>\"
next


\' faster but less readable
for i = 0 to JSONarr.length - 1
	if isObject(JSONarr(i)) then
		set item = JSONarr(i)
		
		if typeName(item) = \"JSONobject\" then
			item.write()
		else
			response.write item
		end if
	else
		item = JSONarr(i)
		response.write item
	end if
	
	response.write \"<br>\"
next

下载源码

通过命令行克隆项目:

git clone https://github.com/rcdmk/aspJSON.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 aspJSON https://www.zuozi.net/31567.html

p2p
上一篇: p2p
SignalR
下一篇: SignalR
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务