我有使用经典asp编写的网站,我需要创建一个页面,它将从第三方网站接收回调,该网站将使用JSON发送三个参数。然后,我需要将这些值存储在数据库中。
我没有JSON的经验,需要一种方法来捕获我的asp页面中的参数。
任何人都有使用JSON的经验。
由于
答案 0 :(得分:1)
我已使用http://www.aspjson.com/将经典ASP与JSON一起使用。
我从上面的网站下载了代码,并将其作为包含文件放在我的页面上:
<!--#INCLUDE file="../dist/asp/aspJSON.asp" -->
然后我可以解析JSON响应并为其分配变量。
我主要使用它来使用Mandrill Email 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数据的结构。