#1 2017-03-07 15:36:31

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

Json de-serialize help needed

Hello,

I am provided following json which seems to be a valid json according to an online json validator.
http://pasted.co/5449b77b

I have setup my records as follows and I am not able to de-serialize it as function returns false to me. Could not find and solve what problem is here. I appreciate any help.

 THasta = packed record
   hastaTC: string;
   adSoyad: string;
 end;

 TGebelikBildirim = packed record
   sysTakipNo: string;
   hekimAdSoyad: string;
   kurumAdi: string;
   kangrubu: Smallint;
   islemzamani: string;
   sonadettarihi: string;
   gonderimZamani: string;
 end;
 TGebelikBildirimleri = TArray<TGebelikBildirim>;

 TSonuc = packed record
   hasta: THasta;
   gebelikBildirim: TGebelikBildirimleri;
 end;
 TSonuclar = TArray<TSonuc>;

 TResult = packed record
   durum: Smallint;
   sonuc: TSonuclar;
   mesaj: string;
 end;

Below is the code piece I am using to de-serialize:

procedure TForm1.Button1Click(Sender: TObject);
var
  JsonRecord: TResult;
  JsonString: string;
  i, i2: Integer;
begin
  ClientDataSet1.EmptyDataSet();

  JsonString := memJson.Text;
  if not RecordLoadJSON(JsonRecord, StringToUTF8(JsonString), TypeInfo(TResult)) then
  begin
    ShowMessage('Json de-serialize failed!');
  end
  else
  begin
    // Some database saving code here
  end;
end;

Thanks & regards,
Ertan

Offline

#2 2017-03-07 21:34:12

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

Re: Json de-serialize help needed

I found problem and its solution.

THasta record was presented me in an earlier sample json with 2 variables in it. Current real-life json includes 3 variables in it. Once I added 3rd variable in THasta record definition everything started to work again.

Thanks.

Offline

#3 2017-03-09 06:16:17

DigDiver
Member
Registered: 2013-04-29
Posts: 137

Re: Json de-serialize help needed

The problem is that j2oIgnoreUnknownProperty option do not work in the record de-serialize.

Offline

Board footer

Powered by FluxBB