当前位置: 首页> 游戏> 网游 > 鸿蒙语言基础类库:【@ohos.uri (URI字符串解析)】

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

时间:2025/7/9 12:09:33来源:https://blog.csdn.net/2301_76813281/article/details/140277967 浏览次数:2次

URI字符串解析

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

导入模块

import uri from '@ohos.uri'  

URI

属性

系统能力:  SystemCapability.Utils.Lang

名称参数类型可读可写说明
schemestring获取URI 的协议部分。
userInfostring获取 URI 的用户信息部分。
hoststring获取 URI 的主机名部分(不带端口)。
portstring获取 URI 的端口部分。
pathstring获取 URI 的路径部分。
querystring获取 URI 的查询部分。
fragmentstring获取 URI 的片段部分
authoritystring获取此URI的解码权限组件部分。
sspstring获取URI的解码方案特定部分。

constructor

constructor(uri: string)

constructor是URI的构造函数。

系统能力:  SystemCapability.Utils.Lang

参数:

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

示例:

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:password@www.qwer.com:8080?query=pppppp');
uriInstance.checkIsAbsolute();

normalize

normalize(): URI

规范化此URI的路径。

系统能力:  SystemCapability.Utils.Lang

返回值:

QQ截图20240705211227.png

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

示例:

const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
let uriInstance1 = uriInstance.normalize();
uriInstance1.path;
关键字:鸿蒙语言基础类库:【@ohos.uri (URI字符串解析)】

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: