I'm sure I saw this in a blog or video recently, but is there a way to convert an object (not an aurelius entity) returned by XData as JSON back into the object within Webcore?
Thanks
I'm sure I saw this in a blog or video recently, but is there a way to convert an object (not an aurelius entity) returned by XData as JSON back into the object within Webcore?
Thanks
Maybe you are asking about functions TJSJSON.parse
(to convert a JSON string into a JavaScript object) and TJSJSON.stringify
(to serialize a JavaScript object to a JSON string)?
No, I use that already. What I was after was parsing the JSON into a Delphi Object in Webcore, so create a TMyObject from a JSON string/JSON Object.
A "Delphi" (*) TMyObject
object has several meta information inside it and it's not very safe to case a JS object to it.
But if you declare a class with external keyword, you can simply case the parsed object directly, Pas2JS allows that:
var
JSObj: TJSObject;
MyObj: TMyObject;
begin
JSObj := JS.ToObject(TJSJSON.parse(JsonString));
MyObj := TMyObject(JSObj)
end;
(*) Delphi between quotes because it's Pas2JS, not Delphi, strictly speaking.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.