Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

VBScript's method tutorial for parsing json strings into json objects

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "VBScript parsing json string into json object method tutorial". In daily operation, I believe that many people have doubts on the method tutorial of VBScript parsing json string into json object. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "VBScript parsing json string into json object method tutorial". Next, please follow the editor to study!

Asp/vbscript parses json characters into json objects. If asp uses jscript to write server-side code to manipulate json strings, vbscript needs MSScriptControl.ScriptControl or server-side jscript as an intermediary.

Method 1 of vbscript parsing json characters into json objects

To use the MSScriptControl.ScriptControl component, please run this example with an IE browser, there will be a security prompt, you need to click "Yes" to allow creation.

Examples of the usage of MSScriptControl.ScriptControl components

Introduction to MSScriptControl.ScriptControl component properties, methods, and events

Dim sc4JsonSub InitScriptControl Set sc4Json = CreateObject ("MSScriptControl.ScriptControl") sc4Json.Language = "JavaScript" sc4Json.AddCode "var itemTemp=null;function getJSArray (arr, index) {itemTemp=arr [index] } "End Sub Function getJSONObject (strJSON) sc4Json.AddCode" var jsonObject = "& strJSON Set getJSONObject = sc4Json.CodeObject.jsonObjectEnd Function Sub getJSArrayItem (objDest,objJSArray,index) On Error Resume Next sc4Json.Run" getJSArray ", objJSArray,index Set objDest = sc4Json.CodeObject.itemTemp If Err.number=0 Then Exit Sub objDest = sc4Json.CodeObject.itemTempEnd Sub Dim strTeststrTest =" {name: "" alonely "", age:24,hello:function () {return 'Hello!' ;}, email: ["ycplxl1314@163.com", "ycplxl1314@gmail.com"], family: {parents: ["Father", "Mother"], toString:function () {return "" Family member " } "Dim objTestCall InitScriptControl' initializes MSScriptControl.ScriptControl component Set objTest = getJSONObject (strTest) 'create JSON object' object property operation msgbox objTest.name&"-"& objTest.age' array operation getJSArrayItem email,objTest.email,0msgbox email' execution method msgbox objTest.hello () msgbox objTest.family.toString ()

The second method of parsing json characters into json objects by vbscript

Using jscript as intermediate

/ / when running on the server, add the runat= "server" attribute Array.prototype.get = function (x) {return this [x];}; function parseJSON (strJSON) {return eval ("(" + strJSON + ")") } Dim json, obj json = "{a:"aaa", b: {name: "bb", value: "text"}, c: ["" item0 "", "item1", "" item2 "]}" Set obj = parseJSON (json), this is the end of the study on "VBScript's method tutorial on parsing json strings into json objects", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report