鸿蒙语言基础类库:【@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:password@www.qwer.com: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:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
let uriInstance1 = uriInstance.normalize();
uriInstance1.path;
相关推荐
2501_920931702 小时前
React Native鸿蒙跨平台采用ScrollView的horizontal属性实现横向滚动实现特色游戏轮播和分类导航
javascript·react native·react.js·游戏·ecmascript·harmonyos
摘星编程4 小时前
React Native鸿蒙版:Drawer抽屉导航实现
react native·react.js·harmonyos
向哆哆4 小时前
打造高校四六级报名管理系统:基于 Flutter × OpenHarmony 的跨端开发实践
flutter·开源·鸿蒙·openharmony·开源鸿蒙
lbb 小魔仙5 小时前
【Harmonyos】开源鸿蒙跨平台训练营DAY9:获取分类数据并渲染
flutter·华为·harmonyos
mocoding5 小时前
Flutter 3D 翻转动画flip_card三方库在鸿蒙版天气预报卡片中的实战教程
flutter·3d·harmonyos
2501_920931705 小时前
React Native鸿蒙跨平台实现推箱子游戏,完成玩家移动与箱子推动,当所有箱子都被推到目标位置时,玩家获胜
javascript·react native·react.js·游戏·ecmascript·harmonyos
qq_177767377 小时前
React Native鸿蒙跨平台数据使用监控应用技术,通过setInterval每5秒更新一次数据使用情况和套餐使用情况,模拟了真实应用中的数据监控场景
开发语言·前端·javascript·react native·react.js·ecmascript·harmonyos
烬头88217 小时前
React Native鸿蒙跨平台应用实现了onCategoryPress等核心函数,用于处理用户交互和状态更新,通过计算已支出和剩余预算
前端·javascript·react native·react.js·ecmascript·交互·harmonyos
小雨青年9 小时前
鸿蒙 HarmonyOS 6 | 系统能力 (06) 构建现代化通知体系 从基础消息到实况
华为·harmonyos
●VON9 小时前
Flutter for OpenHarmony 21天训练营 Day03 总结:从学习到输出,迈出原创第一步
学习·flutter·openharmony·布局·技术