2018-09-28 delphixe10 json

unit Unit3;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,system.json,Vcl.StdCtrls;

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

var
Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
var Root:TJSONObject;
i:integer;
jsonstr:string;
begin

    jsonstr:='{"code":100,"state":"true","data":["hero","npc","pet"]}';
    Root:= TJSONObject.ParseJSONValue(Trim(jsonstr)) as TJSONObject;
     for i:=0 to Root.count-1 do
        begin
           memo1.lines.add(Root.Get(i).JsonString.toString + ' = ' + Root.Get(i).JsonValue.ToString);
        end;
    showmessage( root.GetValue('state').ToString);

end;

end.

你可能感兴趣的:(2018-09-28 delphixe10 json)