码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

-------Unit开始

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses DBXJSON;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
myjson001:TJSONObject;
begin
myjson001:= TJSONObject.Create;
myjson001.AddPair('aa', '111');
myjson001.AddPair('bb', '222');

Memo1.Lines.Text:=myjson001.ToString;
//Memo1.Lines.Text:=myjson001.UnitName ;
FreeAndNil(myjson001);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
a: TJSONArray;
b:TJSONObject;
i:Integer;
begin
a := TJSONArray.Create;
a.Add(1);
a.Add(2);
a.Add('aaa');
a.Add('bbb');

b:=TJSONObject.Create;
b.AddPair('aa','0000');

a.AddElement(b);
Memo1.Text := a.ToString;

 


end;


procedure TForm1.Button3Click(Sender: TObject);
var
myjson001:TJSONObject;
myjson002:TJSONObject;
MyJSONByteReader:TJSONByteReader;
begin
myjson001:= TJSONObject.Create;
myjson001.AddPair('aa', '111');
myjson001.AddPair('bb', '222');

Memo1.Lines.Text:='{myjson001}'+#13#10+myjson001.ToString + #$D#$A; //Memo1.Lines.Text:=myjson001.UnitName ;
myjson002:= TJSONObject.Create;
myjson002.AddPair('cc', '333');
myjson002.AddPair('dd', '444');

Memo1.Lines.Text:='{myjson002}'+#13#10+myjson002.ToString + #$D#$A;

myjson001.AddPair('test',myjson002);
//ShowMessage(myjson001.Get('aa').JsonString.Value +' ' + myjson001.Get('aa').JsonValue.Value );
ShowMessage((myjson001.Get('test').JsonValue as TJSONObject).Get ('cc').ToString );
//Memo1.Lines.Text:='{myjson001嵌入myjson002}'+#13#10+myjson001.ToString ;
Memo1.Lines.Add('{myjson001嵌入myjson002}'+#13#10+myjson001.ToString );
myjson001.RemovePair('test') ;
FreeAndNil(myjson002);
FreeAndNil(myjson001);

 


end;

procedure TForm1.Button4Click(Sender: TObject);

begin
ShowMessage(IntToStr(Pos('1','12122312')));
ShowMessage(StringReplace('11 1 11111',' ','2',[rfReplaceAll]));
end;

end.

------Unit结束------------

——-----Form开始--------

object Form1: TForm1
Left = 891
Top = 540
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 600
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesigned
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 375
Top = 8
Width = 76
Height = 25
Caption = #31616#21333'json'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 375
Top = 51
Width = 76
Height = 25
Caption = 'json'#25968#32452
TabOrder = 1
OnClick = Button2Click
end
object Memo1: TMemo
Left = 0
Top = 0
Width = 369
Height = 300
Align = alLeft
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'Memo1')
TabOrder = 2
end
object Button3: TButton
Left = 375
Top = 104
Width = 75
Height = 25
Caption = 'json'#23884#22871'json'
TabOrder = 3
OnClick = Button3Click
end
object Button4: TButton
Left = 472
Top = 56
Width = 75
Height = 25
Caption = 'Button4'
TabOrder = 4
OnClick = Button4Click
end
end

——-----Form结束--------

posted on 2020-12-16 08:24  码农的笔记  阅读(154)  评论(0编辑  收藏  举报