为什么 UTSJSONObject 类型, 不能通过 obj["xxx"] 和 obj.get("xxx") 的方式获取到对象属性
- Dominant language
- JavaScript
- Stars
- 41.6k
- Forks
- 3.7k
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 6
Description
### 发行方式
App
### 具体平台
Android
### 开发环境
Windows
### 项目创建方式
HBuilderX
### 依赖版本
HbuilderX 4.66
### 问题描述
```
uploadImage(headerImageSrc.value).then((jsonResult) => {
console.log(" jsonResult = ", jsonResult)
})
```
打印结果:
```
18:18:31.961 jsonResult = [UTSJSONObject] {name: "202506221818_1750587507846.png", url: "http://localhost:18000/access/file/2025/06/22/202506221818_1750587507846.png"} at pages/register/register.uvue:197
```
获取 jsonResult 对象的属性一直报错
get 报错信息如下:
```
18:23:21.282 error: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
18:23:21.282 public operator fun String.get(index: Number): Char defined in io.dcloud.uts
18:23:21.282 at pages/register/register.uvue:198:59
18:23:21.282 196| uploadImage(headerImageSrc.value).then((jsonResult) => {
18:23:21.282 197| console.log(" jsonResult = ", jsonResult)
18:23:21.282 198| console.log(" jsonResult.get('data') = ", jsonResult.get('data'));
18:23:21.282 | ^
18:23:21.282 199| })
```
[] 报错信息如下:
```
18:24:26.485 error: No get method providing array access
18:24:26.485 at pages/register/register.uvue:198:55
18:24:26.485 196| uploadImage(headerImageSrc.value).then((jsonResult) => {
18:24:26.485 197| console.log(" jsonResult = ", jsonResult)
18:24:26.485 198| console.log(" jsonResult['data'] = ", jsonResult['data']);
18:24:26.485 | ^
18:24:26.485 199| })
```
### 重现步骤
报错的我都不知道怎么了用了,
uni.request 好好的
换成 uni.uploadFile 的返回值,就各种bug,服了,
```
uni.uploadFile({
url,
filePath,
name: 'files',
success: (response) => {
try {
let jsonResult : UTSJSONObject = JSON.parseObject(response.data)!;
console.log("上传图片返回数据 = ", jsonResult);
if (jsonResult['code'] != 0) {
uni.showToast({
title: jsonResult['msg'] as string,
icon: 'none',
duration: 3000
});
reject(new Error(jsonResult['msg'] as string));
} else {
resolve(jsonResult['data'] as any);
}
} catch (err) {
console.error("解析返回数据失败:", err);
uni.showToast({ title: '返回数据解析失败', icon: 'none' });
reject(err);
}
},
fail: (err) => {
console.error("错误信息:", err)
uni.showToast({ title: "app 错误 " + err.errMsg, icon: 'none' })
reject(err);
}
});
```
我把 jsonResult 对象返回给调用的地方,就不能用了,一直报错. 我真的服了啊, 写一个功能的代码,我就要花至少3个小时处理你们语言方面的bug. 真的无语了, 第一次用这个语言,以为和别的语言没啥区别,谁知道全是bug.这么垃圾,害我头发都白了好多. 这个软件写完后,再也不会用你们这个语言了,太垃圾了
### 期望行为
太垃圾了
### 实际行为
太垃圾了
### 截图或录屏
太垃圾了 啊
Contributor guide
Assessment
This issue has not been assessed yet.