0

I have website written using classic asp and i need to create a page that will receive a callback from a third party site which will be sending three parameters using JSON. I then need to store these values in a database.

I have no experience of JSON and need a way to capture the parameters in my asp page.

Anyone have any experience with JSON.

Thanks

  • You can look here; http://stackoverflow.com/questions/11219/calling-rest-web-services-from-a-classic-asp-page – Pritam Banerjee Jun 13 '16 at 22:40
  • Classic ASP supports Javascript as an alternative to VBScript as a server side language. If I'm dealing with JSON then I find it easier to do this than use the aspjson library http://stackoverflow.com/questions/30538292/asp-json-object-not-a-collection/30546374#30546374 – John Jun 14 '16 at 13:26

1 Answers1

1

I've use http://www.aspjson.com/ for using Classic ASP with JSON.

I downloaded the code from the site above, and have it as an include file on my page:

<!--#INCLUDE file="../dist/asp/aspJSON.asp" -->

Then I can parse through the JSON response and assign variables to it.

I've used it mainly for sending emails using the Mandrill Email API.

The API sends the response in JSON format.

Example response:

[
    {
        "email": "recipient.email@example.com",
        "status": "sent",
        "reject_reason": "hard-bounce",
        "_id": "abc123abc123abc123abc123abc123"
    }
]

Send data to 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 then sends a JSON response - e.g.

[
    {
        "email": "recipient.email@example.com",
        "status": "sent",
        "reject_reason": "hard-bounce",
        "_id": "abc123abc123abc123abc123abc123"
    }
]

I can then process it using:

'process the response JSON data
vAnswer = xmlhttp.responseText

I have to remove the square brackets from the start and end of the JSON response:

vAnswer = replace(vAnswer,"[","")
vAnswer = replace(vAnswer,"]","")

And then do stuff with the data:

'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"))

How you would do it would depend on the structure of the JSON data you are working with.

4532066
  • 2,042
  • 5
  • 21
  • 48