HarmonyOS 鸿蒙Next URL.parseURL解析包含emoji表情的参数时发生异常

HarmonyOS 鸿蒙Next URL.parseURL解析包含emoji表情的参数时发生异常

使用url.URL.parseURL解析url报DecodeURI: invalid character: �错误,Android和iOS可以正常解析,鸿蒙不支持url参数中包含emoji表情吗?

2 回复
import Url from '@ohos.url'
@Entry
@Component
export struct Index123 {

  build() {
    Row() {
      Column() {
        Button('点击')
          .onClick(()=>{
            // let urlParams = "mk:///WebView?fullscreen=true&opaque=true&progress_hidden=true&busy_hidden=false&url=https%3A%2F%2Fintouch-coach-app.uat.mybiz-eks-chn.mkiapp.com%2Femployee"
            let urlParams = "igetcool://xxx.xxx.app/go?params_title=\ud83c\udf400元学热销好课&enableShare=1"
            let decodeURL = decodeURIComponent(urlParams);
            let paramsObject = new Url.URLParams(decodeURL);
            console.log('paramsObject: ', paramsObject)
            // console.log('progress_hidden:'+ paramsObject.get("progress_hidden"))
            // console.log('busy_hidden:'+ paramsObject.get("busy_hidden"))
            // console.log('url:'+ paramsObject.get("url"))
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

更多关于HarmonyOS 鸿蒙Next URL.parseURL解析包含emoji表情的参数时发生异常的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙系统中,当使用URL.parseURL方法解析包含emoji表情的参数时发生异常,这通常是由于URL编码和解码过程中emoji字符的Unicode处理不当所导致的。

Emoji表情通常包含在非ASCII字符集中,如UTF-8编码。在URL中传递这些字符时,应确保它们被正确地编码为百分比编码(例如,%E2%9C%93代表✔)。如果未进行编码,解析器可能无法识别这些特殊字符,从而导致解析异常。

为了解决这个问题,你可以尝试以下步骤:

  1. URL编码:在将参数传递给URL.parseURL之前,确保所有非ASCII字符(包括emoji)都已被正确编码为百分比编码。

  2. 检查解析器实现:确认你使用的URL.parseURL方法是否支持UTF-8编码的URL。如果该方法有特定的限制或要求,你可能需要查找替代的解析方法或库。

  3. 更新和兼容性:确保你的HarmonyOS系统以及任何相关的库或框架都是最新版本,以支持最新的URL解析标准和Unicode字符。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部