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 idpop3收邮件

Delphi xe2创建apple ios程序

Delphi xe5在zip文件中添加某个txt文件并写入文字

Delphi webbrowser1 网页提交按钮执行点击事件

Delphi双击tmemo选择光标所在行

Delphi 根据开始和结束符取得中间字符串

Delphi 使用 idhttp 获取 utf-8 编码的中文网页

Delphi winapi: findwindow、findwindowex - 查找窗口

Delphi webbrowser 表单赋值模拟点击

Delphi memo1 高亮行的范围

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



打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...