最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I generate JSON from "Classic" ASP on IIS? - Stack Overflow

programmeradmin5浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

Yes, 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.

发布评论

评论列表(0)

  1. 暂无评论