From 74cca3fc43716abdc3ec9b0728da4943a6603d89 Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Sat, 9 Sep 2023 19:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=AB=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E4=B8=8B=E6=A0=87keypath=20=E5=8F=96=E5=80=BC=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/JSON.uts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index 2690a94..0de4255 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -104,7 +104,17 @@ export function testJSON() : Result { // TODO 不支持boolean、string,js端需抹平 // expect(JSON.parse('true')!).toEqual(true); // expect(JSON.parse('"foo"')!).toEqual("foo"); - // expect(JSON.parse('null')!).toEqual(null); + // expect(JSON.parse('null')!).toEqual(null); + + const json4 = '{"data":[{"a":"1"},{"a":2},[{"b":true},{"b":"test"}],[1, 2, 3]]}'; + const obj4 = JSON.parse(json4)!; + expect(obj4.getString('data[0].a')).toEqual("1") + expect(obj4.getNumber('data[1].a')).toEqual(2) + expect(obj4.getBoolean('data[2][0].b')).toEqual(true) + expect(obj4.getAny('data[1].a')).toEqual(2) + expect(obj4.getJSON('data[2][1]')).toEqual({"b":"test"}) + expect(obj4.getArray('data[3]')).toEqual([1, 2, 3]) + }) test('parseObject', () => { const json = `{"result":true, "count":42}`; -- GitLab