以下是一個(gè)在 ASP 中使用 ScriptControl 對(duì)象處理 JSON 數(shù)據(jù)的開源代碼示例:
<%
'假設(shè) JSON 數(shù)據(jù)
Dim jsonData
jsonData = '{"name":"John","age":30,"hobbies":["reading","coding","gaming"]}'
'使用 ScriptControl 解析 JSON
Set scriptControl = Server.CreateObject("ScriptControl")
scriptControl.Language = "JScript"
Set parsedObject = scriptControl.Eval("(" + jsonData + ")")
'輸出結(jié)果
Response.Write("Name: " & parsedObject.name & "<br>")
Response.Write("Age: " & parsedObject.age & "<br>")
Dim hobby
For Each hobby In parsedObject.hobbies
Response.Write("Hobby: " & hobby & "<br>")
Next
Set scriptControl = Nothing
Set parsedObject = Nothing
%>
如果服務(wù)器環(huán)境允許安裝第三方庫(kù),以下是使用 JSON for VBScript的示例:
<%
'引用 JSON for VBScript 庫(kù)
'確保在服務(wù)器上正確安裝并注冊(cè)了此庫(kù)
'假設(shè) JSON 數(shù)據(jù)
Dim jsonData
jsonData = '{"name":"John","age":30,"hobbies":["reading","coding","gaming"]}'
'解析 JSON
Set jsonObject = JSON.parse(jsonData)
'輸出結(jié)果
Response.Write("Name: " & jsonObject.name & "<br>")
Response.Write("Age: " & jsonObject.age & "<br>")
Dim hobby
For Each hobby In jsonObject.hobbies
Response.Write("Hobby: " & hobby & "<br>")
Next
Set jsonObject = Nothing
%>
該文章在 2025/1/1 17:05:08 編輯過