diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts index 18773e0b1c49545dfdc8354e6deeeb9d6e8337a9..bcf43842a52148caae6c7690b01e8d9cff4dfcec 100644 --- a/uni_modules/uts-tests/utssdk/JSON.uts +++ b/uni_modules/uts-tests/utssdk/JSON.uts @@ -196,11 +196,53 @@ export function testJSON() : Result { expect(JSON.stringify(Math.PI)).toEqual('3.141592653589793'); expect(JSON.stringify(Math.E)).toEqual('2.718281828459045'); + /** + * add since 2023-09-23 + * 部分出错过的示例场景 + */ + const arr = [{ + "$method": "collection", + "$param": ["type"] as Array, + }, { + "$method": "add", + "$param": [ + [{ + "num": 2, + "tag": "default-tag", + } as UTSJSONObject, { + "num": 3, + "tag": "default-tag", + } as UTSJSONObject] as Array, + ] as Array, + }] as Array + let ret = JSON.stringify({ + $db: arr + }) + expect(ret).toEqual('{"$db":[{"$method":"collection","$param":["type"]},{"$method":"add","$param":[[{"num":2,"tag":"default-tag"},{"num":3,"tag":"default-tag"}]]}]}') + + type Msg = { + id: string, + method: string, + params: any + } + type CallUniMethodParams = { + method : string + args : com.alibaba.fastjson.JSONArray + } + const msg = `{"id":"6fd6ca73-c313-48ac-ad30-87ff4eba2be8","method":"App.callUniMethod","params":{"method":"reLaunch","args":[{"url":"/pages/index/index"}]}}` + const jsonRet2 = JSON.parse(msg)! + + const paramsStr = JSON.stringify(jsonRet2.params) + expect(paramsStr).toEqual('{"args":[{"url":"/pages/index/index"}],"method":"reLaunch"}') + const params = JSON.parse(paramsStr)! + console.warn('params', JSON.stringify(params)) + expect(JSON.stringify(params)).toEqual('{"args":[{"url":"/pages/index/index"}],"method":"reLaunch"}') + }) test('invalidField', () => { - let str = "{\"a+b\":\"test1\",\"a-b\":2,\"class\":true}" + let str = "{\"a+b\" :\"test1\",\"a-b\":2,\"class\":true}" let p = JSON.parseObject(str) expect(p?._class).toEqual(true) expect(p?.a_b).toEqual("test1")