zoukankan      html  css  js  c++  java
  • 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('"u0041u0042u0043"');
      ShowMessage(jo.AsString);
    
      { x }
      jo := SO('"x41x42x43"');
      ShowMessage(jo.AsString);
    
      { u 汉字}
      jo := SO('"u4e07u4e00"');
      ShowMessage(jo.AsString);
    
      { u 后面的数字可大写 }
      jo := SO('"u4E07u4E00"');
      ShowMessage(jo.AsString);
    
      { \、/ }
      jo := SO('"A\B/C"');
      ShowMessage(jo.AsString);
    
      { 	、
     还有 、f、
     }
      jo := SO('"A	B
    C"');
      ShowMessage(jo.AsString);
    
      { "" }
      jo := SO('""ABC""');
      ShowMessage(jo.AsString);
    
      { null 是 JSON 的一种数据类型, 代表空值, 空值也是值的一种 }
      jo := SO('[1,2,3,null]');
      ShowMessage(jo.AsString);
    end;
    
    end.
  • 相关阅读:
    谷歌浏览器最新版下载链接
    第二章 算法——程序的灵魂
    第一章:程序设计和C语言
    C语言程序设计·谭浩强(第四版)第二章课后习题的答案,算法——程序的灵魂
    面向对象之类的其他方法
    面向对象之反射、包装、(定制)
    PyCharm使用秘籍视频
    re模块(详解正则)
    ATM购物车程序项目规范(更新到高级版)
    音乐脚本
  • 原文地址:https://www.cnblogs.com/cpprun/p/4787960.html
Copyright © 2011-2022 走看看