JSON

JSON学习---Json数据的增加,删除,修改

字号+ 作者:H5之家 来源:H5之家 2015-10-20 15:38 我要评论( )

JSON学习---Json数据的增加,删除,修改,学Delphi,delphi编程,delphi编程工具,delphi编程案例,delphi编程源码,delphi编程教程,delphi编程控件,Delphi动画,Delphi

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.

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • JSON学习---Format 与转义字符

    JSON学习---Format 与转义字符

    2015-10-20 18:06

网友点评