#1 2016-10-24 04:07:57

g00gle
Member
Registered: 2016-10-24
Posts: 8

Load from invalid JSON

for example I have my data container like this:

  TGroup = record
    V1: string;
    V2: Integer;
  end;
  TGroups = array of TGroup;
  ..............
  var AR: TDynArray;    Group: TGroups;   Json1, Json2: RawUTF8;
  ..............

  and invalid JSON string like this:

  Json1 :=   PUTF8Char('[{"VX":"TTT","V2":3},{"V1":"VVV","V2":5},{"V1":"","V2":0}]');

  so if i try to fill my Group from Json1 like :

  AR.Init(TypeInfo(TGroups) ,Group);
  AR.LoadFromJSON( PUTF8Char(Json1) );

  then nothing is loaded.

  is there any solution to skip invalid item and load from Json in that part where it has valid data (index 1 and 2) ?

Offline

#2 2016-10-24 12:04:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Load from invalid JSON

When you register the type, TTextWriter.RegisterCustomJSONSerializerFromText() returns a TJSONRecordAbstract instance.
You can set the Options values of the returned instance, as expected.

Offline

Board footer

Powered by FluxBB