jsonProcess:= TJSONArray.Create;
for var i := 0 to processForms.ListView_Processes.Items.
Count - 1 do
begin
tempListItem := processForms.ListView_Processes.Items[i];
var
jsonObject := TJSONObject.Create;
try
jsonObject.AddPair('pid', tempListItem.Caption);
jsonObject.AddPair('processName', tempListItem.SubItems[0]);
jsonProcess.AddElement(jsonObject);
finally
jsonObject.Free;
end;
end;
jsonProcess:= TJSONArray.Create;
for var i := 0 to processForms.ListView_Processes.Items.Count - 1 do
begin
tempListItem := processForms.ListView_Processes.Items[i];
var
jsonObject := TJSONObject.Create;
try
jsonObject.AddPair('pid', tempListItem.Caption);
jsonObject.AddPair('processName', tempListItem.SubItems[0]);
jsonProcess.AddElement(jsonObject);
except
jsonObject.Free;
end;
end;
重点关注finally和except,第二个可以执行成功拿到jsonProcess,而第一个不行
标签:end,AddPair,jsonObject,Delphi,tempListItem,processForms,TJSONObject,使用,jsonProce From: https://www.cnblogs.com/jishaling/p/18518870