JSON 之 SuperObject(5): Format 与转义字符

JSON 之 SuperObject(5): Format 与转义字符




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%; 年龄: %Age%'));


  ShowMessage(jo.Format('%Tel%; %Tel[0]%; %Tel[1]%'));


  ShowMessage(jo.Format('%Children%; %Children.Name%'));


  ShowMessage(jo.Format('[Name], [Age]', '[', ']')); {可更换默认的 % 标记}
end;


//特殊字符
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 汉字}
  jo := SO('"\u4e07\u4e00"');
  ShowMessage(jo.AsString);


  { \u 后面的数字可大写 }
  jo := SO('"\u4E07\u4E00"');
  ShowMessage(jo.AsString);


  { \\、\/ }
  jo := SO('"A\\B\/C"');
  ShowMessage(jo.AsString);


  { \t、\n 还有 \b、\f、\r }
  jo := SO('"A\tB\nC"');
  ShowMessage(jo.AsString);


  { \"" }
  jo := SO('"\"ABC\""');
  ShowMessage(jo.AsString);


  { null 是 JSON 的一种数据类型, 代表空值, 空值也是值的一种 }
  jo := SO('[1,2,3,null]');
  ShowMessage(jo.AsString);
end;


end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值