本文整理自网络,侵删。
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》频道 >>