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 代码查询一个 ip 地址的归属地

Delphi isvaliddatetime、isvaliddate、isvalidtime、isvaliddateday ... 判断时间是否合法

Delphi listbox 使用

Delphi中case语法的使用方法

Delphi base64编码/解码及zlib压缩/解压

Delphi 如何从url提取文件名?

Delphi firedac 连接access mdb数据库的方法

Delphi webbrowser中获取input表单值

Delphi 截取被遮挡的window画面

Delphi firemonkey 学习笔记 �c tpopup 控件的使用

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



打赏

取消

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

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

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

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

评论

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