delphi 解析Json格式

SuperObject 是开源的 Delphi 的 JSON 工具包,可生成 JSON 数据以及进行 JSON 解析。

unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm6 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
  end;

var
  Form6: TForm6;

implementation

uses superobject;

{$R *.dfm}

{ TForm6 }

procedure TForm6.Button1Click(Sender: TObject);
var
  vJson,vItem: ISuperObject;
begin
    vJson := SO('{"classname":"初二一班","pupils":[{"name":"张三","sex":"男"},{"name":"李四","sex":"女"}]}');
    ShowMessage(vJson['classname'].AsString);
    //开始遍历
    for vItem in vJson['pupils'] do
    begin
       ShowMessage(vItem['name'].AsString);
       showMessage(vItem['sex'].AsString);
    end;
end;

end.

SuperObject 下载地址:
http://www.ctdisk.com/file/3537433

你可能感兴趣的:(精彩源码)