鸿蒙语言基础类库:【@ohos.uri (URI字符串解析)】

URI字符串解析

说明: 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。开发前请熟悉鸿蒙开发指导文档gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md点击或者复制转到。

导入模块

复制代码
import uri from '@ohos.uri'  

URI

属性

系统能力: SystemCapability.Utils.Lang

名称 参数类型 可读 可写 说明
scheme string 获取URI 的协议部分。
userInfo string 获取 URI 的用户信息部分。
host string 获取 URI 的主机名部分(不带端口)。
port string 获取 URI 的端口部分。
path string 获取 URI 的路径部分。
query string 获取 URI 的查询部分。
fragment string 获取 URI 的片段部分
authority string 获取此URI的解码权限组件部分。
ssp string 获取URI的解码方案特定部分。

constructor

constructor(uri: string)

constructor是URI的构造函数。

系统能力: SystemCapability.Utils.Lang

参数:

参数名 类型 可读 可写 说明
uri string 入参对象。

示例:

复制代码
var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';

new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080';

toString

toString(): string

系统能力: SystemCapability.Utils.Lang

返回适用于URL中的查询字符串。

返回值:

类型 说明
string 返回网址的字符串序列化。

示例:

复制代码
const url = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString()

equals

equals(other: URI): boolean

判断此URI是否与其他URI对象相等。

系统能力: SystemCapability.Utils.Lang

参数:

参数名 类型 必填 说明
other [URI] 需要比较的URI对象。

返回值:

类型 说明
boolean 返回true表示相等,否则返回false。

示例:

复制代码
const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
uriInstance.equals(uriInstance1);

checkIsAbsolute

checkIsAbsolute(): boolean

判断此URI是否为绝对URI(是否定义了scheme组件)。

系统能力: SystemCapability.Utils.Lang

返回值:

类型 说明
boolean 返回true表示该URI是否为绝对URI。

示例:

复制代码
const uriInstance = new uri.URI('http://username:[email protected]:8080?query=pppppp');
uriInstance.checkIsAbsolute();

normalize

normalize(): URI

规范化此URI的路径。

系统能力: SystemCapability.Utils.Lang

返回值:

类型 说明 HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿
URI 返回一个path被规范化后的URI对象。

示例:

复制代码
const uriInstance = new uri.URI('http://username:[email protected]:8080/path/path1/../path2/./path3?query=pppppp');
let uriInstance1 = uriInstance.normalize();
uriInstance1.path;
相关推荐
康康这名还挺多6 小时前
鸿蒙HarmonyOS list优化一: list 结合 lazyforeach用法
数据结构·list·harmonyos·lazyforeach
晚秋大魔王9 小时前
OpenHarmony 开源鸿蒙南向开发——linux下使用make交叉编译第三方库——nettle库
linux·开源·harmonyos
python算法(魔法师版)13 小时前
.NET 在鸿蒙系统上的适配现状
华为od·华为·华为云·.net·wpf·harmonyos
bestadc14 小时前
鸿蒙 UIAbility组件与UI的数据同步和窗口关闭
harmonyos
枫叶丹415 小时前
【HarmonyOS Next之旅】DevEco Studio使用指南(二十二)
华为·harmonyos·deveco studio·harmonyos next
乱世刀疤19 小时前
深度 |国产操作系统“破茧而出”:鸿蒙电脑填补自主生态空白
华为·harmonyos
沙振宇1 天前
【Web】使用Vue3开发鸿蒙的HelloWorld!
前端·华为·harmonyos
bestadc2 天前
鸿蒙 所有API缩略图鉴
harmonyos
马剑威(威哥爱编程)2 天前
HarmonyOS 5.0 分布式数据协同与跨设备同步
分布式·华为·harmonyos·arkts·harmonyos-next
DONSEE广东东信智能读卡器3 天前
鸿蒙系统使用ArkTS开发语言支持身份证阅读器、社保卡读卡器等调用二次开发SDK
二次开发·sdk·arkts·鸿蒙·身份证阅读器·社保卡读卡器