Hi there

please help i want to consume a json web servvices with classic asp .
i am still very new at web services a simple detailed sample code should do.

thanx in advance...

Dani AI

Generated

For : classic ASP can consume a JSON web service just fine. As hinted, if the service can return XML you should prefer that because classic ASP has native XML parsing (MSXML). If JSON is the only option, the usual pattern is: 1) make the HTTP request with MSXML/WinHTTP, 2) examine the response (status, headers, text), 3) parse the JSON into objects you can read in ASP.

A minimal VBScript example (GET + parse using MSScriptControl). Note: ScriptControl may not be present on all servers and is 32-bit only; eval-ing JSON is unsafe for untrusted input — use a safe parser if you cannot guarantee the data source.

<%
Dim url, xmlhttp, json, sc, obj
url = "https://api.example.com/resource?id=123"

Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.Open "GET", url, False
xmlhttp.setRequestHeader "Accept", "application/json"
xmlhttp.Send

If xmlhttp.Status = 200 Then
    json = xmlhttp.responseText

    Set sc = Server.CreateObject("MSScriptControl.ScriptControl")
    sc.Language = "JScript"
    Set obj = sc.Eval("(" & json & ")")   ' JSON -> JScript object

    Response.Write "Name: " & obj.name & "<br/>"
    ' iterate array: obj.items.length and obj.items(i).id

    Set obj = Nothing
    Set sc = Nothing
Else
    Response.Write "HTTP error: " & xmlhttp.Status & " - " & xmlhttp.statusText
End If

Set xmlhttp = Nothing
%>

Quick tips and gotchas:

  • For POST, set Content-Type: application/json and send a JSON string ("{""k"":""v""}" in VBScript).
  • Many modern APIs require TLS 1.2+; older Windows may fail TLS handshakes.
  • If you see JSONP (callback(...)) strip the wrapper before parsing.
  • If ScriptControl is unavailable, either run the ASP page as server-side JScript and eval() there, or drop in a pure-VBScript JSON parser (several exist) or call into a small .NET/COM wrapper.
  • Always log xmlhttp.Status and xmlhttp.responseText while debugging, and check firewall/outbound rules on the server.

Why would you want to use JSON and why would you want to involve ASP in something that ASP already does so well on its own?

i am trying to interact with a webservice that is rendered in json .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.