Can I generate JSON from “Classic” ASP on IIS?

限于喜欢 提交于 2020-01-03 04:53:06

问题


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?


回答1:


Yes, no problem. It's possible to use the well-known json2.js from json.org 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>



回答2:


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"
}



回答3:


Here is a great article on it which includes some example code: http://www.webdevbros.net/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.



来源:https://stackoverflow.com/questions/9746000/can-i-generate-json-from-classic-asp-on-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!