From 727f9699f5d0e72263f48e53e91bf33ddff18631 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Tue, 22 Aug 2023 15:28:04 +0800 Subject: [PATCH] add JSON.parseArray --- uni_modules/uts-tests/utssdk/JSON.uts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index 6437289..336e7d0 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -99,6 +99,21 @@ export function testJSON() : Result { let obj4 = JSON.parseObject(json3); expect(obj4).toEqual(null); }) + test('parseArray', () => { + const json1 = `[1,2,3]`; + const array1 = JSON.parseArray(json1); + expect(array1).toEqual([1,2,3]); + + const json2 = `[1,"hello world",3]`; + const array2 = JSON.parseArray(json2); + expect(array2).toEqual([1,"hello world",3]); + + + const json3 = `[{"name":"John","id":"30"},{"name":"jack","id":"21"}]`; + const array3 = JSON.parseArray(json3); + expect((array3!![0] as UserJSON).name).toEqual("John"); + + }) test('stringify', () => { const obj = { name: 'John', age: 30 }; const json = JSON.stringify(obj); -- GitLab