我有一个 JSON 字符串,该字符串使用 quicktype 中生成的代码映射到“Pax”的实例中。Quicktype 生成了大约 4000 行代码映射,所以我很高兴并相信它在某种程度上是有效的。我现在想打印这海量数据的一小部分作为开始。这是一个位于 pax.instructions.id 的字符串。
final String paxRaw = response.body;
final Pax xa = paxFromJson(paxRaw);
Run Code Online (Sandbox Code Playgroud)
import 'dart:convert';
Pax paxFromJson(String str) => Pax.fromJson(json.decode(str));
String paxToJson(Pwa data) => json.encode(data.toJson());
class Pax {
Pax({
this.greeting,
this.instructions,
});
String greeting;
List<Instruction> instructions;
factory Pax.fromRawJson(String str) => Pax.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory Pax.fromJson(Map<String, dynamic> json) => Pax(
greeting: json["greeting"] == null ? null : json["greeting"],
instructions: json["instructions"] == null ? null : List<Instruction>.from(json["instructions"].map((x) => Instruction.fromJson(x))),
);
Map<String, dynamic> toJson() …Run Code Online (Sandbox Code Playgroud)