• ASP 下 能作为json输出后js能解密的 escape 函数


    网络上流传的 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
  • 相关阅读:
    洛谷 P4317
    洛谷 P6218
    洛谷 P4999
    洛谷 P2657
    CSP 2020-S2 题解
    2020CSP-S2游记
    Spring Boot中使用WebSocket总结
    防盗链
    JVM JRE和JDK的区别和联系
    Java 注解学习
  • 原文地址:https://www.cnblogs.com/zuike/p/3433947.html
Copyright © 2020-2023  润新知