JSON SuperObject (5) Format and Escape Characters in Delphi
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 =class (TForm) Button1: TButton; Button2: TButton; procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); end ; var Form1: TForm1; implementation {$ R * .dfm} uses SuperObject; // Format procedure TForm1.Button1Click (Sender: TObject); var jo: ISuperObject; begin jo: = SO ('{"Name": "张三", "Age": 88, "Tel": ["111,222"], "Children": {"Name": "张继"}}'); ShowMessage (jo.Format ('Name:% Name%; Age:% Age%')); ShowMessage (jo.Format ('% Tel%;% Tel [0]%;% Tel [1]%')); ShowMessage (jo.Format ('% Children%;% Children.Name%')); ShowMessage (jo.Format ('[Name], [Age]', '[', ']')); {Replaceable default% tag} end ; //Special characters procedure TForm1.Button2Click (Sender: TObject); var jo: ISuperObject; begin jo: = SO; {\ u} jo: = SO ('"\ u0041 \ u0042 \ u0043"'); ShowMessage (jo.AsString); {\ x} jo: = SO ('"\ x41 \ x42 \ x43"'); ShowMessage (jo.AsString); {\ u Chinese character} jo: = SO ('"\ u4e07 \ u4e00"'); ShowMessage (jo.AsString); {\ u can be capitalized} jo: = SO ('"\ u4E07 \ u4E00"'); ShowMessage (jo.AsString); {\\, \ /} jo: = SO ('"A \\ B \ / C"'); ShowMessage (jo.AsString); {\ t, \ n and \ b, \ f, \ r} jo: = SO ('"A \ tB \ nC"'); ShowMessage (jo.AsString); {\ ""} jo: = SO ('"\" ABC \ ""'); ShowMessage (jo.AsString); {null is a data type of JSON, which represents a null value, and a null value is also a kind of value} jo: = SO ('[1,2,3, null]'); ShowMessage (jo.AsString); end ; end .