想问一下关于 JsEncode函数

兼哲 2010-01-16 10:09:40
我有一个asp的 JsEncode


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

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
End Function



不知道,C#怎么去写
...全文
333 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
兼哲 2010-01-17
  • 打赏
  • 举报
回复
没有人知道么?
兼哲 2010-01-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 ferock 的回复:]
我有一个asp的 JsEncode

VBScript codeFunction jsEncode(str)Dim i, j, aL1, aL2, c, p

aL1=Array(&h22,&h5C,&h2F,&h08,&h0C,&h0A,&h0D,&h09)
aL2=Array(&h22,&h5C,&h2F,&h62,&h66,&h6E,&h72,&h74)For i=1ToLen(str)
p=True
c=Mid(str, i,1)For j=0To7If c=Chr(aL1(j))Then
jsEncode= jsEncode&"\"&Chr(aL2(j))
p=FalseExitForEndIfNextIf pThenDim a
a= AscW(c)If a>31And a<127Then
jsEncode= jsEncode& cElseIf a>-1Or a<65535Then
jsEncode= jsEncode&"\u"&String(4-Len(Hex(a)),"0")&Hex(a)EndIfEndIfNextEnd Function


不知道,C#怎么去写
[/Quote]

没有效果,这个我知道,但是,我需要的是序列化成安全的Js 字符串

例如:
Json数据转换出来是


{site_com_intro:"<p><embed type=\"application\/x-shockwave-flash\" src=\"http:\/\/127.0.0.1\/www\/Thinkart\/Mr_Think\/TK-Admin\/lib\/upfile\/2009122949736365.swf\" wmode=\"opaque\" quality=\"high\" bgcolor=\"#ffffff\" menu=\"false\" play=\"true\" loop=\"true\" height=\"100\" width=\"200\" \/><\/p><p><br \/><\/p><p><a href=\"http:\/\/127.0.0.1\/www\/Thinkart\/Mr_Think\/TK-Admin\/lib\/upfile\/2009122949757449.txt\">\u70B9\u51FB\u6253\u5F00\u94FE\u63A5<\/a><br \/><\/p>"}

mngzilin 2010-01-16
  • 打赏
  • 举报
回复
C#有现成的函数:
Server.HtmlEncode(str);
HttpUtility.HtmlEncode(str);

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧