7***@tmp.dcloud.io
7***@tmp.dcloud.io
  • 发布:2025-09-17 09:55
  • 更新:2025-09-17 11:47
  • 阅读:106

【报Bug】UTSJSONObject.parse如果遇到包含对象的数组,就会返回null

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: Windows 10 Pro 22H2 19045.5011

HBuilderX类型: 正式

HBuilderX版本号: 4.76

手机系统: Android

手机系统版本号: Android 10

手机厂商: 小米

手机机型: 小米10

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

type Item = {x: number, y: string}
type D = {
list: Item[]
}

const json: UTSJSONObject = .... // from uni.request
const result = json.parse<D>(); //will be null

预期结果:

const result = json.parse<D>(); //Parse correctly

实际结果:

const result = json.parse<D>(); //will be null

bug描述:

UTSJSONObject.parse方法,如果遇到里面包含对象的数组,就会返回null

2025-09-17 09:55 负责人:无 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

提供一下可以说明问题的最简代码 我看一下

7***@tmp.dcloud.io

7***@tmp.dcloud.io (作者)

也有可能是嵌套的泛型引起的:

type Item = {x: string};

type Response<D> = {status: string, data: D}

const result = utsJSONObj.parse<Response<Item[]>>(); // result is null

utsJSONObj来自uni.request<UTSJSONObject>....

console.log出来的utsJSONObj的结构和Response<Item[]>是一致的,但是parse返回null

要回复问题请先登录注册