uniapp-X 对象动态取值

有个对象,例如

复制代码
const data={
						age:12,
						list:[
							1,2,3,4
						]
					}

有个函数如下

复制代码
export function getValueByPath(obj:UTSJSONObject, path:string):any {
  const current= obj.getAny(path) as any;
    // 返回最终的值
    return current;
}

期待

通过执行getValueByPath("xx.xx")来访问内部的值,不管存不存在,不管返回类型

实现

复制代码
//一定要as any,不能as unkonw,编译成android会报错,
//开发工具:web提示是as unkonw再 as UTSJSONObject
//记得不要这样!!!!!!,一定要as any

const obj=this.obj as any  as UTSJSONObject;
this.readData=JSON.stringify(getValueByPath(obj,this.path));
try{
	const realData=JSON.parse(this.readData)
//取出来后再判断类型即可
	console.log("typeof",typeof realData,realData instanceof Array)
}catch(err){
	console.error("err",err)
}
相关推荐
2501_915921433 小时前
如何在苹果手机上面进行抓包?iOS代理抓包,数据流抓包
android·ios·智能手机·小程序·uni-app·iphone·webview
00后程序员张4 小时前
iOS APP 性能测试工具,监控CPU,实时日志输出
android·ios·小程序·https·uni-app·iphone·webview
2501_915921435 小时前
360移动端性能监控实践QDAS-APM(iOS篇)
android·macos·ios·小程序·uni-app·cocoa·iphone
CDwenhuohuo5 小时前
uniapp 安卓原生截图保存到相册跟api服务器 canvas实现 plus.nativeObj.Bitmap实现
android·uni-app
WebCsDn_TDCode5 小时前
uniapp-uview-plus
uni-app
Rysxt_1 天前
uni-app x 教程:下一代跨平台开发框架
uni-app·uni-app x
游戏开发爱好者81 天前
2025年iOS应用上架App Store全指南,开发者必看
android·ios·小程序·https·uni-app·iphone·webview
集成显卡1 天前
CVE检索工具 | 开发一款检索漏洞信息的小程序
网络安全·小程序·uni-app·cve·漏洞信息
jaqi.l1 天前
uni-app 小程序全局挂载分享功能,并动态配置页面是否可以分享
vue.js·小程序·uni-app
2501_915106321 天前
HBuilderX 项目上架 iOS app上架 App Store 的关键流程
android·ios·小程序·https·uni-app·iphone·webview