unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses SuperObject; //添加 procedure TForm1.Button1Click(Sender: TObject); var jo: ISuperObject; i: Integer; begin jo := TSuperObject.Create; for i := 0 to 9 do jo.I[‘N‘ + IntToStr(i)] := i; ShowMessage(jo.AsJSon(True)); for i := 0 to 9 do jo.S[‘N‘ + IntToStr(i)] := IntToStr(i); ShowMessage(jo.AsJSon(True)); for i := 0 to 9 do jo.B[‘N‘ + IntToStr(i)] := Odd(i); ShowMessage(jo.AsJSon(True)); for i := 0 to 9 do jo.D[‘N‘ + IntToStr(i)] := i / 2; ShowMessage(jo.AsJSon(True)); for i := 0 to 9 do jo.O[‘N‘ + IntToStr(i)] := SO(‘{"A":"B"}‘); ShowMessage(jo.AsJSon(True)); jo.Clear; ShowMessage(jo.AsJSon(True)); end; //修改与删除 procedure TForm1.Button2Click(Sender: TObject); var jo: ISuperObject; str: string; begin jo := SO(‘{"Name":"张三", "Age":88}‘); ShowMessage(jo.AsJSon(False, False)); jo.S[‘Name‘] := ‘李四‘; jo.I[‘Age‘] := 18; ShowMessage(jo.AsJSon(False, False)); jo.Delete(‘Age‘); ShowMessage(jo.AsJSon(False, False)); jo.D[‘Size‘] := 1.83; ShowMessage(jo.AsJSon(False, False)); end; //TSuperArray 的增、删、改与查看 procedure TForm1.Button3Click(Sender: TObject); var jo,item: ISuperObject; ja: TSuperArray; i: Integer; str: string; begin jo := SO(‘{"爱好":["编程","打球"]}‘); ShowMessage(jo.AsJSon(False, False)); jo.A[‘爱好‘].Add(SO(‘看电视‘)); ShowMessage(jo.AsJSon(False, False)); ja := jo.A[‘爱好‘]; ja.Add(SO(‘游泳‘)); ShowMessage(jo.AsJSon(False, False)); ja.Insert(0, SO(‘睡觉‘)); ShowMessage(jo.AsJSon(False, False)); ja.Delete(0); ShowMessage(jo.AsJSon(False, False)); ja.D[0] := 3.14; ShowMessage(jo.AsJSon(False, False)); ja.O[0] := SO(‘{}‘); ShowMessage(jo.AsJSon(False, False)); str := ‘‘; for i := 0 to ja.Length - 1 do str := Format(‘%s %s‘, [str, ja.S[i]]); ShowMessage(Trim(str)); str := ‘‘; for item in jo[‘爱好‘] do str := Format(‘%s %s‘, [str, item.AsString]); ShowMessage(Trim(str)); ja.Clear; ShowMessage(jo.AsJSon(False, False)); end; end.
转自:https://www.cnblogs.com/del/archive/2009/10/23/1588819.html
原文:https://www.cnblogs.com/mqcode/p/13446049.html