I receive the following JSON from a request:
{
"cdPlayer": 3,
"nmPlayer": "Player Name",
"dtCreate": "2016-08-24T22:53:31.687",
"dtChange": null,
"idStatus": true
}
I would like to load convert dtCreate and dtChange to TDateTime. How to properly do this? There is no TJSONDateTime
to cast the GetValue
. Below is my current code where I'm casting it to a plain String.
procedure TfrmPrincipal.btnInfoClick(Sender: TObject);
var
jsonRoot: TJSONObject;
tokenRequest: TRESTRequest;
tokenResponse: TRESTResponse;
tokenClient: TRESTClient;
tokenAutenticacao: TOAuth2Authenticator;
begin
tokenClient := TRESTClient.Create(nil);
tokenRequest := TRESTRequest.Create(nil);
tokenResponse := TRESTResponse.Create(nil);
tokenAutenticacao := TOAuth2Authenticator.Create(nil);
try
tokenRequest.Client := tokenClient;
tokenRequest.Response := tokenResponse;
tokenRequest.Method := TRESTRequestMethod.rmPUT;
tokenClient.Authenticator := tokenAutenticacao;
tokenAutenticacao.TokenType := TOAuth2TokenType.ttBEARER;
tokenAutenticacao.AccessToken := 'token_string';
tokenClient.BaseURL := 'http://host/url/method';
tokenRequest.Execute;
jsonRoot:= TJSONObject.ParseJSONValue(tokenResponse.JSONText) as TJSONObject;
Memo1.Lines.Add('cdPlayer => ' + jsonRoot.GetValue('cdPlayer').Value);
Memo1.Lines.Add('nmPlayer=> ' + jsonRoot.GetValue('nmPlayer').Value);
Memo1.Lines.Add('dtCreate=> ' + jsonRoot.GetValue('dtCreate').Value);
Memo1.Lines.Add('dtChange=> ' + jsonRoot.GetValue('dtChange').Value);
Memo1.Lines.Add('idStatus=> ' + (jsonRoot.GetValue('idStatus') as TJSONBool).ToString);
finally
tokenAutenticacao.Free;
tokenResponse.Free;
tokenRequest.Free;
tokenClient.Free;
end;
end;
I'm using Delphi XE 10 Seatle. Thanks
EDIT
As far as the duplicate goes, I had no ideia that this Data format was ISO 8601. That's why I couldn't find the answer anywhere through Google. Maybe my question will help some others that, like me, didn't know as well.