delphi 解析Json格式

来源:互联网 发布:网络彩票最新消息动态 编辑:程序博客网 时间:2024/05/16 06:19

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

unit Unit6;interfaceuses  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;implementationuses 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