Questions about TJSJSON and JSValue

Hi there, I have two questions:

  1. An error message is shown "[Error] RequestorUnit.pas(237): identifier not found "TJSJSON"
    when I try to run the code "Result := TVerifyResponse(TJSJSON.parse(req.responseText));", why?

2.The type of TJSXMLHttpRequest.response is JSValue and the value is {"errorCode": 0}.The code below:

type
TVerifyResponse = record
errorCode: Integer;
end;

......

var
req: TJSXMLHttpRequest;
vr: TVerifyResponse;
begin
...
try
req:=await(TJSXMLHttpRequest, WebHTTPRequest1.perform);
expcept
.....
end;

vr:=TVerifyResponse(req.response);

console.log(vr);
end;

The code runs failed, an error message is in console:

Uncaught (in promise) TypeError: Cannot read property 'errorCode' of null
at Object.$assign (RequestorUnit.pas:62)
at Object.DoVerify (RequestorUnit.pas:237)

Any idea about this??

Source code is here:RequestorUnit.pas (6.4 KB)

Thanks.

  1. You need to use the unit JS in your Webcore unit to access TJSJSON

  2. I'm not sure you can just cast the response as this will be JSON, and in web terms that is an object in itself.

  1. This is in the unit JS, add it to the uses list
  2. It looks like the response is a JSON object, you can't just cast this to a record

Thank you @Weetch_Russell @brunofierens

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.