Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hi ,
The JSON array behaves very strange:
------------------test code of TestInputAsJson--------------------------------------------
logger.debug("jsonParam1 " + JSON.stringify(jsonParam1));
logger.debug("jsonParam1.World.length " + jsonParam1.World.length);
logger.debug("jsonParam1.World[0] " + jsonParam1.World[0]);
logger.debug("jsonParam2 " + JSON.stringify(jsonParam2));
logger.debug("jsonParam2.length " + jsonParam2.length);
--------------------call service TestInputAsJson-----------------------------------------------
me.InputAsJson({
jsonParam1: { Hello: "bbb", World:[1 ,2,3] } /* JSON */,
jsonParam2: [1,2,3] /* JSON */
});
---------------------log result------------------------------------------------------
jsonParam1 {"Hello":"bbb","World":{}} ==>The JSON array is not serialized
jsonParam1.World.length 3 ==>The JSON array is actual existing although its not visible
jsonParam1.World[0] 1 ==>The JSON array is accessible if it's part of JSON object
jsonParam2 {"array":{}} ==> The JSON array become empty if it's the root
jsonParam2.length undefined ==> And it's not accessible neither.
---------------------------------------------------------------------------------------------
Why does the JSON array behavior so strange and the root JSON array even doesn't work ?
ThingWorx 8.5.5
Regards,
Sean
Solved! Go to Solution.
Sean,
Can you use a JSON.parse internally in the logger statements, like this?
JSON.stringify(JSON.parse(jsonParam1)
It's something related to internal Javascript-Java conversions we do, I'm not the best authority to answer why this happens.
There's an article about this here: https://www.ptc.com/en/support/article/CS330294 , planned for fix in 9.1.0, but please confirm first if the above workaround works for you.
Sean,
Can you use a JSON.parse internally in the logger statements, like this?
JSON.stringify(JSON.parse(jsonParam1)
It's something related to internal Javascript-Java conversions we do, I'm not the best authority to answer why this happens.
There's an article about this here: https://www.ptc.com/en/support/article/CS330294 , planned for fix in 9.1.0, but please confirm first if the above workaround works for you.