Harmony OS【获取本地json数据的方法】

news/2025/3/22 4:02:39/
// 文件名称 MapContent.json
// 文件路径 resource/rawfile/MapContent.json
[{"title": "准备与学习","brief": "加入HarmonyOS生态,注册成为开发者,通过HarmonyOS课程了解基本概念和基础知识,轻松开启HarmonyOS的开发旅程。","materials": [{"subtitle": "HarmonyOS简介","knowledgeBase": [{"type": "准备","title": "注册账号"},{"type": "准备","title": "实名认证"}]},{"subtitle": "赋能套件介绍","knowledgeBase": [{"type": "指南","title": "开发"}]}]},{"title": "构建应用","brief": "为了帮助开发者更好的理解HarmonyOS提供的能力,我们对重点功能提供了开发指导,辅助开发者完成应用的开发。","materials": [{"subtitle": "开发工具","knowledgeBase": [{"type": "指南","title": "DevEco Studio"}]},{"subtitle": "开发语言","knowledgeBase": [{"type": "指南","title": "ArkTS"}]},{"subtitle": "开发框架","knowledgeBase": [{"type": "指南","title": "ArkTS"},{"type": "视频教程","title": "ArkUI之属性动画"}]},{"subtitle": "HarmonyOS云开发","knowledgeBase": [{"type": "指南","title": "体验HarmonyOS云开发"},{"type": "指南","title": "云开发"},{"type": "视频教程","title": "HarmonyOS云开发"}]}]},{"title": "应用测试","brief": "HarmonyOS应用/服务开发完成后,在发布到应用/服务市场前,还需要对应用进行:漏洞、隐私、兼容性、稳定性、性能等测试,确保HarmonyOS应用/服务纯净、安全,给用户带来更好的使用体验。","materials": [{"subtitle": "","knowledgeBase": [{"type": "指南","title": "云测试"},{"type": "指南","title": "开放式测试"}]}]},{"title": "上架","brief": "HarmonyOS应用/服务开发、测试完成后,将应用/服务发布至应用市场,用户可以通过应用市场、负一屏等渠道获取到对应的HarmonyOS应用/服务。","materials": [{"subtitle": "应用发布","knowledgeBase": [{"type": "指南","title": "发布HarmonyOS应用"},{"type": "指南","title": "发布元服务"},{"type": "指南","title": "分阶段发布"},{"type": "视频教程","title": "发布HarmonyOS应用"},{"type": "视频教程","title": "发布元服务"}]}]},{"title": "运营增长","brief": "HarmonyOS应用/服务发布以后,通过数据及时了解运营情况、质量表现,制定增长策略,借助App Linking、崩溃服务等能力,实现应用及服务的用户增长以及质量提升。","materials": [{"subtitle": "应用发布","knowledgeBase": [{"type": "指南","title": "应用分析"},{"type": "指南","title": "App Linking"},{"type": "指南","title": "崩溃服务"},{"type": "视频教程","title": "远程配置"},{"type": "视频教程","title": "发布元服务"}]}]},{"title": "商业变现","brief": "HarmonyOS应用/服务发布以后,通过数据及时了解运营情况、质量表现,制定增长策略,借助App Linking、崩溃服务等能力,实现应用及服务的用户增长以及质量提升。","materials": [{"subtitle": "","knowledgeBase": [{"type": "指南","title": "流量变现 "},{"type": "指南","title": "联运服务"},{"type": "指南","title": "付费服务"},{"type": "指南","title": "结算指南"}]}]},{"title": "更多","brief": "","materials": [{"subtitle": "","knowledgeBase": [{"type": "指南","title": "常见问题"},{"type": "指南","title": "版本说明"}]}]}
]
// 引入依赖
import { util } from "@kit.ArkTS"
import { BusinessError } from "@kit.BasicServicesKit"@Component
struct Index {@State section:[] = []private getSection() {try {getContext(this).resourceManager.getRawFileContent('MapContent.json', (error: BusinessError, value: Uint8Array) => {const textDecoder = util.TextDecoder.create("utf-8");const res = textDecoder.decodeToString(value, { stream: false });this.section = JSON.parse(res); // 进行转换})} catch (error) {console.error(`报错了:${error}`)}}// 初始话生命周期,在build函数之前执行aboutToAppear(): void {this.getSection();}}

技术点小结

aboutToAppear() {} : 创建自定义组件的新实例后,在执行其build()函数之前执行。 可以运行修改状态变量,更改后将在后续执行build()函数中生效
ps: 自定义组件的生命周期: aboutToAppear


http://www.ppmy.cn/news/1581050.html

相关文章

前端面试:ajax 和 xhr 是什么关系?

在前端开发中,AJAX(Asynchronous JavaScript and XML)和 XHR(XMLHttpRequest)是两个密切相关但有些不同的概念。以下是对这两者的详细解释及其关系: 1. AJAX 定义:AJAX 是一个用于创建异步 we…

自定义uniapp组件,以picker组件为例

编写目的 本文说明基于vue3定义uniapp组件的关键点: 1、一般定义在components文件夹创建组件,组件与页面已经没有明确的语法格式区别,所以可以与页面的语法保持一致 ; 2、组件定义后使用该组件的页面不需要引用组件即可使用&am…

将MySQL数据同步到Elasticsearch作为全文检索数据的实战指南

在现代应用中,全文检索是一个非常重要的功能,尤其是在处理大量数据时。Elasticsearch 是一个强大的分布式搜索引擎,能够快速地进行全文检索、分析和可视化。而 MySQL 作为传统的关系型数据库,虽然能够处理结构化数据,但…

Milvus 向量数据库使用示例

一、环境准备 # 安装依赖(需提前配置 Docker 版 Milvus) pip install pymilvus python-dotenv transformers torch tqdm二、文本分割与向量化 from glob import glob from tqdm import tqdm from transformers import AutoTokenizer, AutoModel import…

Lora 中 怎么 实现 矩阵压缩

Lora 中 怎么 实现 矩阵压缩 1. 导入必要的库 import torch import re from datasets import Dataset from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer, \get_cosine_schedule_with_warmup, EarlyStoppingCallback from peft

Java-模块一

Java之父 詹姆斯高斯林 开发三步骤 编写(后缀为java)编译(javac,生成一个.class文件)运行(java class文件,不需要后缀名了) 文档注释和注释的区别 文档注释(Documen…

持续集成(CI)/持续部署(CD)

背景 如果每个人都在自己的分支上工作,然后定期合并到主分支。可能会导致集成时出现很多问题,比如代码冲突、功能不兼容等等。CI的核心思想是通过自动化构建和测试,尽早发现问题,减少集成风险,提高开发效率。 优点 …

通向AGI的未来之路!首篇2D/视频/3D/4D统一生成框架全景综述(港科大中山等)

文章链接: https://arxiv.org/pdf/2503.04641 摘要 理解并复现现实世界是人工通用智能(AGI)研究中的一个关键挑战。为实现这一目标,许多现有方法(例如世界模型)旨在捕捉支配物理世界的基本原理&#xff0…