private function httpEncoding(param:String):String{ //转码
return encodeURIComponent(param);
}
private function openSelfStr(deleteStr:String):String{ //解码
return decodeURIComponent(deleteStr);
}
-------------------------------------------------------------------------------------------------------
在URL后面加?传递的参数里有中文的时候,后台就取不到值。这时就需要对其进行转码
Flex中转码的函数:escape,encodeURI,encodeURIComponent
Flex中相应解码函数:unescape,decodeURI,decodeURIComponent
一、escape对0-255以外的unicode值进行编码时输出%u****格式。
其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
二、encodeURIComponent是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持
PS:
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
return encodeURIComponent(param);
}
private function openSelfStr(deleteStr:String):String{ //解码
return decodeURIComponent(deleteStr);
}
-------------------------------------------------------------------------------------------------------
在URL后面加?传递的参数里有中文的时候,后台就取不到值。这时就需要对其进行转码
Flex中转码的函数:escape,encodeURI,encodeURIComponent
Flex中相应解码函数:unescape,decodeURI,decodeURIComponent
一、escape对0-255以外的unicode值进行编码时输出%u****格式。
其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
二、encodeURIComponent是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持
PS:
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
本文介绍了在Flex中如何处理URL参数编码的问题,详细解释了escape、encodeURI与encodeURIComponent三种编码方式的区别,并提供了对应的解码方法。文章还特别指出,在传递包含中文等特殊字符的参数时,应使用encodeURIComponent进行编码。
1792

被折叠的 条评论
为什么被折叠?



