I'm doing an API call using TWebHttpRequest and then parsing the response string to a TJSObject, but when I try to get a value from the TJSObject, it comes back as a JSValue. I need to take this JSValue and store it in a Delphi Boolean variable.
Here's my code:
LoginAPI.Execute(
procedure(AResponse: string; AReq: TJSXMLHttpRequest)
var
JS: TJSObject;
loginSuccess: Boolean;
begin
JS := TJSJSON.parseObject(AResponse);
loginSuccess := JS.Properties['loginSuccess'];
console.log(loginSuccess);
end
);
I'm getting the following error:
[Error] Incompatible types: got "JSValue" expected "Boolean"
This error happens on loginSuccess := JS.Properties['loginSuccess'] when I try to get the value and put it into the Boolean variable.
When I do console.log(JS.Properties['loginSuccess']) then I can see that the value is definitely a Boolean in the browser console. So I just need to know how to get it as a Boolean in Delphi.
I tried doing a .AsBoolean, but that doesn't work:
loginSuccess := JS.Properties['loginSuccess'].AsBoolean;
And the error I get then is:
[Error] illegal qualifier "." after "Properties:JSValue"
So, how can I convert this JSValue to a Boolean?
If you know the property's value is definitely
Boolean, then you can just cast it directly toBooleanlike this: