任何用于在经典 ASP 中解析 JSON 的好库? [英] Any good libraries for parsing JSON in Classic ASP?

查看:31
本文介绍了任何用于在经典 ASP 中解析 JSON 的好库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够找到无数的库用于在经典 ASP (VBScript) 中生成 JSON,但我还没有找到任何用于解析的库.>

我想要一些可以传递 JSON 字符串并返回某种类型的 VBScript 对象(数组、Scripting.Dictionary 等)

谁能推荐一个在经典 ASP 中解析 JSON 的库?

解决方案

请记住,Classic ASP 包括 JScript 和 VBScript.有趣的是,您可以使用 JScript 解析 JSON,并直接在 VBScript 中使用生成的对象.

因此,可以使用规范的https://github.com/douglascrockford/JSON-js/blob/master/json2.js 在零修改的服务器端代码中.

当然,如果您的 JSON 包含任何数组,则解析完成后这些数组仍将是 JScript 数组.您可以使用点表示法从 VBScript 访问 JScript 数组的内容.

<%@Language="VBScript" %><%选项显式%><script language="JScript" runat="server" src='path/to/json2.js'></script><%调暗 myJSONmyJSON = Request.Form("myJSON")//"[ 1, 2, 3 ]"设置 myJSON = JSON.parse(myJSON)//[1,2,3]Response.Write(myJSON)//1,2,3Response.Write(myJSON.[0])//1Response.Write(myJSON.[1])//2Response.Write(myJSON.[2])//3%>

I've been able to find a zillion libraries for generating JSON in Classic ASP (VBScript) but I haven't been to find ANY for parsing.

I want something that I can pass a JSON string and get back a VBScript object of some sort (Array, Scripting.Dictionary, etc)

Can anyone recommend a library for parsing JSON in Classic ASP?

解决方案

Keep in mind that Classic ASP includes JScript as well as VBScript. Interestingly, you can parse JSON using JScript and use the resulting objects directly in VBScript.

Therefore, it is possible to use the canonical https://github.com/douglascrockford/JSON-js/blob/master/json2.js in server-side code with zero modifications.

Of course, if your JSON includes any arrays, these will remain JScript arrays when parsing is complete. You can access the contents of the JScript array from VBScript using dot notation.

<%@Language="VBScript" %>
<%
Option Explicit
%>

<script language="JScript" runat="server" src='path/to/json2.js'></script>

<%

Dim myJSON
myJSON = Request.Form("myJSON") // "[ 1, 2, 3 ]"
Set myJSON = JSON.parse(myJSON) // [1,2,3]
Response.Write(myJSON)          // 1,2,3
Response.Write(myJSON.[0])      // 1
Response.Write(myJSON.[1])      // 2
Response.Write(myJSON.[2])      // 3
%>

这篇关于任何用于在经典 ASP 中解析 JSON 的好库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆