【发布时间】:2021-10-13 03:58:25
【问题描述】:
我正在尝试反序列化来自 Web 服务的 JSON 响应。响应采用类型良好的对象数组的形式。例如,我使用的是 songster.com。
在以下(摘录)代码中,显然TSongsterResponse 不正确,因为我要收回一个集合。但是array of TSongsterResponse 和TSongsterList 都不会编译。
interface
type
TSongsterResponse = class
public
id: integer;
title: string;
end;
type TSongsterList = array of TSongsterResponse;
implementation
procedure Sample(AJson: string);
begin
// What goes here to get an array of TSongsterResponse?
FSomething := TJson.JsonToObject<?????>(RESTResponse1.Content);
end;
【问题讨论】:
-
@RemyLebeau 我试着按照那个例子,但我希望从每个数组值中获取一个类型化的对象,而那个例子是从一个通用的 TJsonObject 中提取一个字符串值。我看不到如何修改内部循环来为每个数组项生成一个 TSongsterResponse。
-
查看我刚刚发布的答案