JSON to Variant

Top 

Example code : JSON2Variant

function JSON2Variant(AResponse: string): Variant;

begin

 asm

   @Result=JSON.parse(@AResponse);

 end;

end;

 

procedure TForm1.W3Button4Click(Sender: TObject);

 var

   mJSON: String;

   mData: Variant;

Begin

mJSON := '{"RowID":10,"FirstName":"abc","LastName":"def","YearOfBirth":20,"YearOfDeath":30,'+

         '"Sexe":1,"Simple":{"F":"","G":[],"H":{"H1":0,"H2":"","H3":{"H3a":false,"H3b":null}},"I":"","J":['+

         '{"J1":1,"J2":"","J3":"reLast"}]}}';

mData:=JSON2Variant(mJSON);

 

{ Accessing the elements of the JSON }

   WriteLn('mData.firstName = '   + mData.FirstName);

   WriteLn('mData.lastName = '    + mData.LastName);

   WriteLn('mData.YearOfBirth = ' + mData.YearOfBirth);

end;

mData.firstName = abc

mData.lastName = def

mData.YearOfBirth = 20