codegooglecom / easyasp

Automatically exported from code.google.com/p/easyasp
0 stars 0 forks source link

关于Json转码的问题 #53

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
js安全代码,可以参考这个function,并且请把Json这里的unicode��
�掉,这样js可以
直接输出。

Function Easp_JsEncode(ByVal str)
        Dim i, j, aL1, aL2, c, p,jsEncode

        aL1 = Array(&h22, &h5C, &h2F, &h08, &h0C, &h0A, &h0D, &h09)
        aL2 = Array(&h22, &h5C, &h2F, &h62, &h66, &h6E, &h72, &h74)
        For i = 1 To Len(str)
            p = True
            c = Mid(str, i, 1)
            For j = 0 To 7
                If c = Chr(aL1(j)) Then
                    jsEncode = jsEncode & "\" & Chr(aL2(j))
                    p = False
                    Exit For
                End If
            Next

            If p Then
                Dim a
                a = AscW(c)
                If a > 31 And a < 127 Then
                    jsEncode = jsEncode & c
                ElseIf a > -1 Or a < 65535 Then
                    jsEncode = jsEncode & "\u" & String(4 - Len(Hex(a)), "0") & Hex(a)
                End If
            End If
        Next
        Easp_JsEncode=jsEncode
End Function

Original issue reported on code.google.com by ferock on 25 Jan 2010 at 2:42

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
顺便提一下,希望能够提供,Json,自定义构建的方法。
毕竟通过表结构输出,虽然方便,但是,在属性名称上,会��
�露字段泄露的安全隐患。

Original comment by ferock on 25 Jan 2010 at 2:52

GoogleCodeExporter commented 9 years ago

Original comment by ferock on 25 Jan 2010 at 7:04

Attachments:

GoogleCodeExporter commented 9 years ago
Easp的JsEncode本身就是这样处理的,谢谢。可能你使用的是旧��
�本。
Easp提供了Json类,你可以自己构建你的Json。另外,Easp.db.Json��
�实并不是通过表结构输出,而是通
过Recordset对象输出的,所以字段名是可以自己构造的,比如 
Select UserName As uname,......
对于复杂的应用,还是建议使用Easp.Json.New自己构造Json对象。

Original comment by Tainray@gmail.com on 26 Jan 2010 at 3:23

GoogleCodeExporter commented 9 years ago
我用的不是旧版本

我想,你没有明白我的意思。
2.1 版本输出的json,不能被js直接使用

Original comment by ferock on 26 Jan 2010 at 3:56

GoogleCodeExporter commented 9 years ago
{ "myRecord" : [{"id":"1", "username":"1http%3A//%u4E2D%u6587",
"password":"1%u5BC6%u7801"}]}

1http%3A//%u4E2D%u6587,这个字符串在js里不能被解析成中文

Original comment by ferock on 26 Jan 2010 at 4:11

GoogleCodeExporter commented 9 years ago
而且,2.1版本,Easp.Json.New不支持,刚刚测试过

Original comment by ferock on 26 Jan 2010 at 4:16

GoogleCodeExporter commented 9 years ago
2.2已经开始测试了,的确替换掉了,不用回复我了,麻烦你��
�

Original comment by ferock on 26 Jan 2010 at 4:25