TQJson序列和还原clientdataset.data

TQJson是QDAC开源项目的JSON对象,其特点是跨平台,功能强大。

序列

procedure TForm2.Button2Click(Sender: TObject);
var
AJson: TQJson;
begin
AJson := TQJson.Create;
try
AJson.AsVariant := ClientDataSet1.Data;
if SaveDialog1.Execute then
AJson.SaveToFile(SaveDialog1.FileName, teUtf8, true);
finally
AJson.Free;
end;
end;

还原

procedure TForm2.Button3Click(Sender: TObject);
var
AJson: TQJson;
function Json2Bytes: TBytes;
var
I: Integer;
begin
SetLength(Result, AJson.Count);
for I := 0 to AJson.Count - 1 do
Result[I] := AJson[I].AsInteger;
end;

begin
AJson := TQJson.Create;
try
if OpenDialog1.Execute then
begin
AJson.LoadFromFile(OpenDialog1.FileName);
ClientDataSet1.Close;
ClientDataSet1.Data := Json2Bytes;
end;
finally
AJson.Free;
end;
end;

你可能感兴趣的:(client)