HarmonyOS 鸿蒙Next TextDecoder接口调用失败

发布于 1周前 作者 vueper 来自 鸿蒙OS

HarmonyOS 鸿蒙Next TextDecoder接口调用失败

JS API参考文档里面的demo,运行于remote emulator: P40 Pro

export function test() {
  var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true});
  var result = new Uint8Array(6);
  result[0] = 0xEF;
  result[1] = 0xBB;
  result[2] = 0xBF;
  result[3] = 0x61;
  result[4] = 0x62;
  result[5] = 0x63;
  console.log("input num:");
  for(var j= 0; j < 6; j++) {
    console.log(`/// result[j] = ${result[j]}`);
  }
  var retStr = textDecoder.decode( result , {stream:false});
  console.log("retStr = " + retStr);
}

执行报错:

20026-22596/? E 03900/Ace: [v8_utils.cpp (JsStdDumpErrorAce)] [DUMP] TypeError: textDecoder.decode is not a function
20026-22596/? E 03900/Ace: [v8_utils.cpp (JsStdDumpErrorAce)]   var retStr = textDecoder.decode(result);  (pages/index.js:161:29-30
2668-19821/? I HwApsManagerConfig: registerCallbackLocked success, pkgName:com.leptonets, callback_count:3
2668-19821/? I HwApsManagerConfig: doCallbackAtFirstRegisterLocked, start ! pkgName:com.leptonets
2668-5118/? E AGPService: AGPServiceClient: [ConnectLocked]: get service failed
2668-5118/? D AGPService: AGPServiceClient: reconnected
2668-5118/? E AGPService: AGPManagerImpl: [SetLcdEvent]: can not get service
20026-22596/? E 03900/Ace: [v8_utils.cpp (JsStdDumpErrorAce)] [DUMP] TypeError: textDecoder.decode is not a function

这个是模拟器还不支持这个接口?


更多关于HarmonyOS 鸿蒙Next TextDecoder接口调用失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

7 回复
楼主你好,经测试是支持的,你可以检查下环境再次尝试。测试环境:IDE版本:3.0 Beta2 , JS API7 ,远程 P40pro . 测试代码:

```javascript
// [@ts-nocheck](/user/ts-nocheck)
import util from '[@ohos](/user/ohos).util';

export default {
  data: {
    title: ""
  },
  onInit() {
    this.title = this.$t('strings.world');
    var textDecoder = new util.TextDecoder("utf-8", {
      ignoreBOM: true
    });
    var result = new Uint8Array(6);
    result[0] = 0xEF;
    result[1] = 0xBB;
    result[2] = 0xBF;
    result[3] = 0x61;
    result[4] = 0x62;
    result[5] = 0x63;
    console.log("input num:");
    for (var j = 0; j < 6; j++) {
      console.log(result[j]);
    }
    var retStr = textDecoder.decode(result, {
      stream: false
    });
    console.log("retStr = " + retStr);
  }
}

参考链接:https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-apis-util-0000001126516726

更多关于HarmonyOS 鸿蒙Next TextDecoder接口调用失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


API 11 decode 是空的?

开发者您好,请查看JS API参考文档开头文字说明支持最低API的版本,然后检查自己使用IDE工具使用的API版本。

API version 7开始支持,应用IDE配置的API版本也是7,不行。

希望HarmonyOS能继续推出更多实用的功能,满足用户的不同需求。

欢迎开发小伙伴们进来帮帮楼主

针对HarmonyOS(鸿蒙)Next TextDecoder接口调用失败的问题,可能的原因及解决方法如下:

  1. 接口版本不兼容:确保你使用的TextDecoder接口版本与鸿蒙系统版本兼容。鸿蒙系统不断更新,新的接口可能在新版本中引入,而旧版本可能不支持。检查鸿蒙系统的更新日志和文档,确认接口版本。

  2. 权限问题:某些接口调用可能需要特定的权限。检查你的应用是否已经声明了必要的权限,并在设置中授予了这些权限。

  3. 参数错误:检查传递给TextDecoder接口的参数是否正确。错误的参数类型或格式可能导致接口调用失败。

  4. 系统Bug:鸿蒙系统本身可能存在Bug,导致特定接口无法正常工作。关注鸿蒙系统的官方Bug跟踪系统或社区论坛,看是否有其他用户报告了相同的问题,并等待官方修复。

  5. 环境问题:确保你的开发环境(如IDE、SDK等)配置正确,且支持当前的鸿蒙系统版本。

如果上述方法均无法解决问题,可能是更深层次的系统或应用问题。此时,建议直接联系鸿蒙系统的官方客服以获取更专业的帮助。官网客服地址是: 如果问题依旧没法解决请联系官网客服。

回到顶部