firedac数据集数据序列为JSON

时间:2022-06-13 06:30:02

firedac数据集数据序列为JSON

FIREDAC数据库引擎充分地考虑了跨平台和跨语言的支持。

因此,FIREDAC数据集可以序列为BIN\XML\JSON,三种格式。

firedac数据集数据序列为JSON字符串:

procedure TForm1.Button1Click(Sender: TObject);
begin
var ss: TStringStream := TStringStream.Create('', TEncoding.UTF8);
FDQuery1.SaveToStream(ss, sfJSON);
Memo1.Text := ss.DataString;
ss.Free;
end;

  

数据集序列后的JSON字符串:

{
"FDBS":
{"Version":15,
"Manager":
{"UpdatesRegistry":true,
"TableList":
[
{"class":"Table","Name":"FDQuery1","SourceName":"tunit","SourceID":1,"TabID":0,"EnforceConstraints":false,"MinimumCapacity":50,
"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,"Original":{"unitid":"11","unitname":"个"}},{"RowID":1,"Original":{"unitid":"12","unitname":"双"}}
]
}
],"RelationList":[],"UpdatesJournal":{"Changes":[]}
}
}
}

  

  如上的JSON数据,其他开发语言当然是能解析并还原出数据的。