Asp/vbscript to parse JSON characters into JSON objects, it's easy if ASP uses JScript to write server-side code to manipulate the JSON string. VBScript requires Msscriptcontrol.scriptcontrol or server-side JScript as an intermediate.
VBScript method of parsing JSON characters into JSON objects
Using the Msscriptcontrol.scriptcontrol component, run this example with IE, and there will be a security prompt, which you need to click "Yes" to allow creation.
Examples of usages of msscriptcontrol.scriptcontrol components
Msscriptcontrol.scriptcontrol component Properties, methods, Events Introduction
Copy Code code as follows:
<script language= "VBScript" >
Dim Sc4json
Sub 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.jsonObject
End 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.itemTemp
End Sub
Dim strtest
Strtest = "{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 Objtest
Call Initscriptcontrol ' Initialize Msscriptcontrol. ScriptControl components
Set objtest = getjsonobject (strtest) ' Creates a JSON object
' Object property action
MsgBox objtest.name& "-" &objtest.age
' Array operation
Getjsarrayitem email,objtest.email,0
MsgBox Email
' Methods of execution
MsgBox Objtest.hello ()
MsgBox ObjTest.family.toString ()
</script>
VBScript method of parsing JSON characters into JSON objects two
Using JScript as an intermediate
Copy Code code as follows:
<script language= "JavaScript" >//when running on the server side, increase runat= "Server" property
Array.prototype.get = function (x) {return this[x];
function Parsejson (Strjson) {return eval ("+ Strjson +"));}
</script>
<script language= "VBScript" >
Dim JSON, obj
JSON = "{A:" "AAA" ", b:{Name:" "BB", Value: "" Text ""}, c:["" Item0 "", "" Item1 "", "" Item2 ""]} "
Set obj = Parsejson (JSON)