lazarus資料序列為JSON

delphi中间件發表於2024-04-25

uses DataSet.Serialize, fpjson;

var obj:tjsonobject;

procedure TForm1.Button1Click(Sender: TObject);
begin
  uniquery1.Close;
  uniquery1.SQL.clear;
  uniquery1.sql.Add('select top 2 * from tunit');
  uniquery1.Open;
  memo1.text:=uniquery1.ToJSONArrayString;  //[{ "unitid" : "10", "unitname" : "雙" }, { "unitid" : "1000", "unitname" : "床" }]
  //obj:=tjsonobject.Create;
  //obj.add('ds1',uniquery1.ToJSONArray);
  //memo1.Text:=obj.AsJSON; //{ "ds1" : [{ "unitid" : "10", "unitname" : "雙" }, { "unitid" : "1000", "unitname" : "床" }] }
  ///obj.free;
end;                           

  

相關文章