lazarus json

uses fpjson, jsonparser

function jsonArray(json: string): tjsonarray;
begin
  result := getjson(json) as tjsonarray;
end;

function jsonObject(json: string): tjsonobject;
begin
  result := getjson(json) as tjsonobject;
end;  
             
function jsonFromFile(filename: string): tjsonobject;
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  try
    sl.LoadFromFile(filename);
    Result := getjson(sl.Text) as tjsonobject;
  finally
    sl.Free;
  end;
end;      

var jo: tjsonobject;
var ja: tjsonarray; 
jo.add();
jo.get();       
ja := jo.Find('dataset') as tjsonarray;
for i := 0 to ja.Count - 1 do
jo := ja.Items[i] as tjsonobject;

 

posted @ 2024-06-30 17:01  delphi中间件  阅读(20)  评论(0编辑  收藏  举报