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;

相关阅读 >>

Delphi 如何将颜色值转换为灰度颜色值?

Delphi 在桌面上画图

Delphi listview基本用法大全

Delphi xe 打开andorid gps设置

Delphi 匹配中文的正则表达式

Delphi edit只能输入数字或小数点

Delphi url编码与解码工具附代码

Delphi 读写文本

获取网络日期

Delphi 从记事本导入记录

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...