网络上流传的 vbsEscape UnEscape都只针对asp而言,js传递给asp时可进行转义解码,但asp输出json时如果用这些函数进行编码的话,js是无法正常解码的。

下面是经过实际验证可用的asp escape函数:

原文地址:http://www.webdevbros.net/2007/04/26/json-character-escaping-function-in-classic-asp/

'******************************************************************************************

'' @SDESCRIPTION:   takes a given string and makes it JSON valid (http://json.org/)

'' @AUTHOR: Michael Rebec

'' @DESCRIPTION:    all characters which needs to be escaped are beeing replaced by their

''                  unicode representation according to the

''                  RFC4627#2.5 - http://www.ietf.org/rfc/rfc4627.txt?number=4627

'' @PARAM:          val [string]: value which should be escaped

'' @RETURN:         [string] JSON valid string

'******************************************************************************************

public function escapeJSON(val)

    cDoubleQuote = &h22

    cRevSolidus = &h5C

    cSolidus = &h2F

 

    for i = 1 to (len(val))

        currentDigit = mid(val, i, 1)

        if asc(currentDigit) > &h00 and asc(currentDigit) < &h1F then

            currentDigit = escapeJSONSquence(currentDigit)

        elseif asc(currentDigit) >= &hC280 and asc(currentDigit) <= &hC2BF then

            currentDigit = "u00" + right(padLeft(hex(asc(currentDigit) - &hC200), 2, 0), 2)

        elseif asc(currentDigit) >= &hC380 and asc(currentDigit) <= &hC3BF then

            currentDigit = "u00" + right(padLeft(hex(asc(currentDigit) - &hC2C0), 2, 0), 2)

        else

            select case asc(currentDigit)

                case cDoubleQuote: currentDigit = escapeJSONSquence(currentDigit)

                case cRevSolidus: currentDigit = escapeJSONSquence(currentDigit)

                case cSolidus: currentDigit = escapeJSONSquence(currentDigit)

            end select

        end if

        escapeJSON = escapeJSON & currentDigit

    next

end function

 

function escapeJSONSquence(digit)

    escapeJSONSquence = "u00" + right(padLeft(hex(asc(digit)), 2, 0), 2)

end function 

 

function padLeft(value, totalLength, paddingChar)

    padLeft = right(clone(paddingChar, totalLength) & value, totalLength)

end function

 

public function clone(byVal str, n)

    for i = 1 to n : clone = clone & str : next

end function

ASP 下 能作为json输出后js能解密的 escape 函数的更多相关文章

  1. List多个字段标识过滤 IIS发布.net core mvc web站点 ASP.NET Core 实战:构建带有版本控制的 API 接口 ASP.NET Core 实战:使用 ASP.NET Core Web API 和 Vue.js 搭建前后端分离项目 Using AutoFac

    List多个字段标识过滤 class Program{  public static void Main(string[] args) { List<T> list = new List& ...

  2. 刷新各ifream当前页,下拉项改变触发事件js,给选中项加背景色js

    <script type="text/javascript" language="javascript"> //刷新框架各页面 function r ...

  3. (转)JSON数据格式和js操作json总结

    原:http://niutuku.com/tech/javaScript/273643.shtml JSON数据格式和js操作json总结 来源:niutuku.com |         vince ...

  4. json进阶(一)js读取解析JSON类型数据

    js读取解析JSON类型数据 一.什么是JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式,同 ...

  5. ASP.NET中使用JSON方便实现前台与后台的数据交换

    ASP.NET中使用JSON方便实现前台与后台的数据交换 发表于2014/9/13 6:47:08  8652人阅读 分类: ASP.NET Jquery extjs 一.前台向后台请求数据 在页面加 ...

  6. [Asp.net mvc]Asp.net mvc 使用Json传递数据

    在之前的练习中一直是直接传递的Model到后台或是单个数据到后台,今天在使用中遇到了点问题,不能使用Model传递到后台,但又要实现多个数据到后台,实验了多次有了以下的解决方案,给自己留个笔记. 功能 ...

  7. JavaScript中使用JSON,即JS操作JSON总结

    JSON(JavaScript Object Notation 对象标记) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生 ...

  8. asp.net中利用JSON进行增删改查中运用到的方法

    //asp.net中 利用JSON进行操作, //增加: //当点击“增加链接的时候”,弹出增加信息窗口,然后,在窗体中输入完整信息,点击提交按钮. //这里我们需要考虑这些:我会进行异步提交,使用j ...

  9. ASP.NET Core launchsettings.json 文件

    ASP.NET Core launchsettings.json 文件 在本节中,我们将讨论在 ASP.NET Core 项目中launchsettings.json文件的重要性. launchset ...

随机推荐

  1. 修改浏览器User-Agent

    IE: 1,F12进入开发人员工具 2,工具->更改用户代理字符串->自定义 3,在"友好名称"中填入"IE9",在"用户代理字符串&qu ...

  2. oracle数据库没有监听服务与实例服务(OracleServicesXX)的解决方法

    不知道为什么,可能是因为更新系统的原因,过了一段时间,想打开oracle服务,发现居然没有任何oracle有关的服务了,但以前的数据库文件什么的都在,心想肯定是可以复原的,应该只是注册表的问题罢了.在 ...

  3. react 编写组件 五

    看以下示例了解如何定义一个组件 // 定义一个组件LikeButton var LikeButton = React.createClass({ // 给state定义初始值 getInitialSt ...

  4. hibernate篇章四-- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置

    我们在搭建环境的时候,在配置文件中有一个属性标签为: <property name="hibernate.hbm2ddl.auto">     </propert ...

  5. UNIX线程之间的关系

    我们在一个线程中经常会创建另外的新线程,如果主线程退出,会不会影响它所创建的新线程呢?下面就来讨论一下. 1.  主线程等待新线程先结束退出,主线程后退出.正常执行. 示例代码: #include & ...

  6. Web开发必备资源汇总[转]

    导读:原文来自< Best “must know” open sources to build the new Web>,译文由酷壳网陈皓整理编译< 开源中最好的Web开发的资源 & ...

  7. UVA 11549 CALCULATOR CONUNDRUM(Floyd判圈算法)

    CALCULATOR CONUNDRUM   Alice got a hold of an old calculator that can display n digits. She was bore ...

  8. UVA 1401 Remember the Word(用Trie加速动态规划)

    Remember the Word Neal is very curious about combinatorial problems, and now here comes a problem ab ...

  9. caffe源码阅读(3)-Datalayer

    DataLayer是把数据从文件导入到网络的层,从网络定义prototxt文件可以看一下数据层定义 layer { name: "data" type: "Data&qu ...

  10. 【CF493E】【数学】Vasya and Polynomial

    Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...