我使用 http://www.aspjson.com/ 将 Classic ASP 与 JSON 结合使用。
我从上面的网站下载了代码,并将其作为包含文件放在我的页面上:
<!--#INCLUDE file="../dist/asp/aspJSON.asp" -->
然后我可以解析 JSON 响应并为其分配变量。
我主要将它用于使用 Mandrill 电子邮件 API 发送电子邮件。
API 以 JSON 格式发送响应。
示例响应:
[
{
"email": "recipient.email@example.com",
"status": "sent",
"reject_reason": "hard-bounce",
"_id": "abc123abc123abc123abc123abc123"
}
]
向 Mandrill 发送数据...
vurl = "https://mandrillapp.com/api/1.0/messages/send.json"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.open "POST", vurl, false
xmlhttp.setRequestHeader "Content-type","application/json"
xmlhttp.setRequestHeader "Accept","application/json"
'send JSON data to the API
xmlhttp.send oJSON.JSONoutput()
Mandrill 然后发送 JSON 响应 - 例如
[
{
"email": "recipient.email@example.com",
"status": "sent",
"reject_reason": "hard-bounce",
"_id": "abc123abc123abc123abc123abc123"
}
]
然后我可以使用:
'process the response JSON data
vAnswer = xmlhttp.responseText
我必须从 JSON 响应的开头和结尾删除方括号:
vAnswer = replace(vAnswer,"[","")
vAnswer = replace(vAnswer,"]","")
然后对数据进行处理:
'load the incoming JSON data using aspJSON
Set oJSON = New aspJSON
'Load JSON string
oJSON.loadJSON(vAnswer)
'set variable values from the incoming data
json_email = ap(oJSON.data("email"))
json_status = ap(oJSON.data("status"))
json_reject_reason = ap(oJSON.data("reject_reason"))
json_id = ap(oJSON.data("_id"))
您将如何做取决于您正在使用的 JSON 数据的结构。