Convert A JSON To TW Object Of Type ANY
Solution 1:
The first thing I would note that in my 8.6 install, calling JSON.parse() just works, so you don't need the community toolkit. That being noted, that approach seems to encounter what is likely the same bug as you are seeing when you try to do it using ANY or Record.
Based on the error it seems that the underlying TWObject won't let you reference member fields that are not explicitly declared. In my tests, using the JSON String -
var json='{ "name" : "Andrew", "value" : "42"}';
I tried -
tw.local.myNvp = JSON.parse(json);
tw.local.myAny = JSON.parse(json);
The first one which was parsing into a variable of type "NameValuePair" from the system data toolkit worked. The 2nd which was trying to parse into an "ANY" failed. I also tried with Record to see if we could get there, but that failed as well.
My suggestion would be to return the raw JSON to the caller and have them invoke the parse line above. I'm assuming the caller is expecting a specific type back, which means the variable isn't an Abstract type, so the parse call should work.
-Andrew Paier
Post a Comment for "Convert A JSON To TW Object Of Type ANY"