I have some logic I want to run on the server-side. It's implemented in Javascript, and I'd like to use it to generate and emit JSON, to allow a REST-api for a web app I'm producing.
Development is on Windows7 and IIS. I know IIS still supports ASP, which can be implemented in Javascript.
Is it possible for an ASP classic page to emit JSON?
I have some logic I want to run on the server-side. It's implemented in Javascript, and I'd like to use it to generate and emit JSON, to allow a REST-api for a web app I'm producing.
Development is on Windows7 and IIS. I know IIS still supports ASP, which can be implemented in Javascript.
Is it possible for an ASP classic page to emit JSON?
Share Improve this question asked Mar 16, 2012 at 23:59 CheesoCheeso 193k106 gold badges485 silver badges734 bronze badges3 Answers
Reset to default 4Yes, no problem. It's possible to use the well-known json2.js from json within a Javascript-based "classic ASP" page.
Per ejemplo:
<%@ language="Javascript" %>
<script language="Javascript" runat="server" src='json2.js'></script>
<script language="Javascript" runat="server">
(function() {
scriptEngineInfo = function () {
var s = {
engine : ScriptEngine(),
version: {
major: ScriptEngineMajorVersion(),
minor:ScriptEngineMinorVersion()
},
build: ScriptEngineBuildVersion()
};
return s;
}
}());
var x = scriptEngineInfo();
var d = new Date();
x.Timestamp = d.valueOf();
Response.Write (JSON.stringify(x));
</script>
This is a basic example of how to create a .json
file with classic ASP
.
<%
Response.ContentType = "application/json"
Response.Write("{ ""responseCode"": ""success"", ""accountNumber"": ""78527511"", ""ID_Code"": ""654321"", ""version"": ""1""}")
%>
having as a result:
{
"responseCode": "success",
"accountNumber": "78527511",
"ID_Code": "654321",
"version": "1"
}
Here is a great article on it which includes some example code: http://www.webdevbros/2007/04/26/generate-json-from-asp-datatypes/
Its best to put you data in a properly structured array and this code will show you have to take an array and output JSON formatted text.