#1 2021-05-03 21:37:56

ertank
Member
Registered: 2016-03-16
Posts: 163

JSON De-serialization help needed

Hello,

I am using Delphi 10.3, mORMot SynopseCommit.inc value '1.18.6244'

I could not figure why I get FAILED! message for following simple JSON string

{
  "optionUuid": "57202ea4-cc62-4eff-bbea-fa5be41449ee",
  "optionName": "Tuzsuz",
  "optionPrice": 5.2,
  "isSelected ": true
}

Using a code like below:

  TOrderProductNote = packed record
    optionUuid: string;
    optionName: string;
    optionPrice: Double;
    isSelected: Boolean;
  end;

procedure TForm2.Button1Click(Sender: TObject);
var
  Response: TOrderProductNote;
  TempString: string;
begin
  TempString := '{"optionUuid": "57202ea4-cc62-4eff-bbea-fa5be41449ee","optionName": "Tuzsuz","optionPrice": 5.2,"isSelected ": true}';
  if not SynCommons.RecordLoadJSON(Response, RawUTF8(TempString), TypeInfo(TOrderProductNote)) then
    ShowMessage('FAILED!')
  else
    ShowMessage('OK');
end;

My debugging, I see de-serialization fails on "isSelected", but I could not understand why.

Any help is appreciated.

Thanks & Regards,
Ertan

Offline

#2 2021-05-03 21:42:27

ertank
Member
Registered: 2016-03-16
Posts: 163

Re: JSON De-serialization help needed

Nevermind, just figured, right after I post that there is a space character in raw JSON string for

"isSelected "

Cost me a lot of time until I could actually see that.

Sorry for the noise.

Offline

#3 2021-05-04 04:27:24

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 228
Website

Re: JSON De-serialization help needed

I know the feeling though, thanks for making us feel better ;-)

Offline

Board footer

Powered by FluxBB