From fceb7727283b7f4058fb3ad412a9f69059791637 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Mon, 30 Sep 2024 15:59:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E5=88=86=20UTSJSONObject.toJSONString=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uts-tests/utssdk/UTSJSONObject.uts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts index 007c97a..12b3f87 100644 --- a/uni_modules/uts-tests/utssdk/UTSJSONObject.uts +++ b/uni_modules/uts-tests/utssdk/UTSJSONObject.uts @@ -36,6 +36,38 @@ export function testUTSJSONObject() : Result { expect(result.toJSONObject().toJSONString()).toEqual('{"opt":"xxxx","service":{"array":[{"name":"xxx","type":0}],"name":"0xxxb34fb","type":0}}'); + type TestData = { + num:number; + num2:number; + str:string; + } + + let data1:TestData = { + num:1, + num2:2.369, + str:'test' + } + let data2 = JSON.parse(JSON.stringify(data1)) + + expect(data2!.toJSONString()).toEqual('{"str":"test","num":1.0,"num2":2.369}') + + type TestData4 = { + name:string, + data:any, + } + + let data4 : TestData4 = { + name:"张三", + data:data1 + } + + let data5 = { + data4 :data4 + } + + expect(data5!.toJSONString()).toEqual('{"data4":{"data":{"num":1,"num2":2.369,"str":"test"},"name":"张三"}}') + + // #endif }) -- GitLab