FDMEMTABLE将修改后的数据序列为JSON

FDMEMTABLE将修改后的数据序列为JSON

procedure TForm1.Button3Click(Sender: TObject);
var
  memtable: TFDMemTable;
  ms: TStringStream;
begin
  memtable := FDMemTable2;
  memtable.CachedUpdates := True;
  if memtable.State in dsEditModes then
    memtable.Post;
  if memtable.ChangeCount = 0 then
    Exit;
  memtable.ResourceOptions.StoreItems := [siDelta, siMeta];
  ms := TStringStream.Create('', TEncoding.UTF8);
  try
    memtable.SaveToStream(ms, sfJSON);
    Memo1.Text := ms.DataString;
  finally
    ms.Free;
    memtable.ResourceOptions.StoreItems := [siDelta, siMeta, siData];
  end;
end;

  JSON字符串如下:

{
	"FDBS":
	{"Version":15,
		"Manager":
		{"UpdatesRegistry":true,
			"TableList":
			[{"class":"Table","Name":"qryOpen","SourceName":"tunit","SourceID":1,"TabID":0,"EnforceConstraints":false,"MinimumCapacity":50,"CheckNotNull":false,
				"ColumnList":
				[
					{"class":"Column","Name":"unitid","SourceName":"unitid","SourceID":1,"DataType":"AnsiString","Size":4,"Searchable":true,
					 "Base":true,"OInUpdate":true,"OInWhere":true,"OInKey":true,"OriginColName":"unitid","SourcePrecision":4,"SourceSize":4},
					{"class":"Column","Name":"unitname","SourceName":"unitname","SourceID":2,"DataType":"AnsiString","Size":6,"Searchable":true,
					 "AllowNull":true,"Base":true,"OAllowNull":true,"OInUpdate":true,"OInWhere":true,"OriginColName":"unitname","SourcePrecision":6,"SourceSize":6}
				],"ConstraintList":[],"ViewList":[],
				"RowList":
				[
					{"RowID":0,"RowState":"Modified","RowPriorState":"Unchanged","Original":{"unitid":"11","unitname":"个"},"Current":{"unitid":"11","unitname":"国"}},
					{"RowID":2,"RowState":"Deleted","Original":{"unitid":"66","unitname":"66"}},
					{"RowID":3,"RowState":"Inserted","Current":{"unitid":"13","unitname":"是"}}
				]
			 }
			],"RelationList":[],"UpdatesJournal":{"SavePoint":3,"Changes":[{"TabID":0,"RowID":2,"ChangeNumber":0},{"TabID":0,"RowID":3,"ChangeNumber":1},{"TabID":0,"RowID":0,"ChangeNumber":2}]}
		}
	}
}

  

 不论使用哪种开发语言,修改后的数据只要如此组织成JSON,就可以提交给FIREDAC中间件。 

  

posted @ 2019-03-31 11:53  delphi中间件  阅读(1093)  评论(0编辑  收藏  举报