- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi FDQuery遍历输出 json
Uses System.JSON;
Var
FDQuery : TFDQuery;
field_name,Collumnname,CollumnValue : String;
I: Integer;
LJSONObject:TJsonObject;
begin
FDQuery := TFDQuery.Create(nil);
try
FDQuery.Connection := FDConnection1;
FDQuery.SQL.Text := query;
FDQuery.Active := True;
FdQuery.BeginBatch;//Don't update external references until EndBatch;
FDQuery.First;
LJSONObject:= TJSONObject.Create;
while (not FDQuery.EOF) do
begin
for I := 0 to FDQuery.FieldDefs.Count-1 do
begin
CollumnName := FDQuery.FieldDefs[I].Name;
CollumnValue := FDQuery.FieldByName(CollumnName).AsString;
LJSONObject.AddPair(TJSONPair.Create(TJSONString.Create( CollumnName),TJSONString.Create(CollumnValue)));
end;
FDQuery.Next;
//FDQuery.Refresh; that's wrong
FdQuery.EndBatch;
finally
FDQuery.Free;
Showmessage(LJSonObject.ToString);
end;
end;