公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【ASP】JSON object class 3.8.1 讀寫類

admin
2024年12月12日 17:17 本文熱度 1520

MIT license: http://opensource.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


該文章在 2024/12/12 17:36:55 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 国产精品欧美亚洲韩国日本 | 国产自在自线午夜精品视频在 | 成人精品久久 | 97色色网| 国产91成人免费网站 | 国产女主播精品大秀系列在线 | 国产成人亚洲欧美日韩精品 | 国产91久久九九免费精品无码 | 精品日韩国产欧美视频 | 国产在线观看d妇在野外 | 操老逼欧美一区二区 | 国产麻豆精品久久久 | 国产成人av免费观看 | 国产日韩精品欧美一区 | 国产一级精品无码 | 2025久久精品永久免费 | 精品国产免费看久久久 | 国产一级毛片大陆片看看 | 国产精品日韩无卡一区二区 | 国产午夜毛片v区一区二区三区 | 国产91av视频在线播放 | 国产一区免费看久久无码精品 | 丰满少妇高潮惨叫久久久 | 国产精品成人av在线不卡 | 国产91精品久久二区二区 | 91精品人妻少妇无码影院 | 国产精品无码专区 | 国产精品亚洲香蕉第五区 | 国产精品日韩精 | 国产极品美女高潮无套在线观看 | 精品人妻系列无码人妻网 | 国产一区二区无码专区 | 国产在线观看精 | av中文在线播放 | 精品91自产拍在线观看一区 | 国产精品成人av在线观看春天 | 国产成人精品日本亚洲18图 | 91麻豆精品国产91久久久久 | 国产成人高清激情视频在线观看 | 国产av成人无码精品网站 | 国产成人一区二区三区毛片 |