您可以根据需要使用this website 生成模型类。这是我从那里得到的。
// To parse this JSON data, do
//
// final welcome = welcomeFromMap(jsonString);
import 'dart:convert';
Welcome welcomeFromMap(String str) => Welcome.fromMap(json.decode(str));
String welcomeToMap(Welcome data) => json.encode(data.toMap());
class Welcome {
Welcome({
this.data,
this.included,
});
List<Datum> data;
List<Included> included;
factory Welcome.fromMap(Map<String, dynamic> json) => Welcome(
data: List<Datum>.from(json["data"].map((x) => Datum.fromMap(x))),
included: List<Included>.from(json["included"].map((x) => Included.fromMap(x))),
);
Map<String, dynamic> toMap() => {
"data": List<dynamic>.from(data.map((x) => x.toMap())),
"included": List<dynamic>.from(included.map((x) => x.toMap())),
};
}
class Datum {
Datum({
this.id,
this.type,
this.attributes,
this.relationships,
});
String id;
String type;
DatumAttributes attributes;
Relationships relationships;
factory Datum.fromMap(Map<String, dynamic> json) => Datum(
id: json["id"],
type: json["type"],
attributes: DatumAttributes.fromMap(json["attributes"]),
relationships: Relationships.fromMap(json["relationships"]),
);
Map<String, dynamic> toMap() => {
"id": id,
"type": type,
"attributes": attributes.toMap(),
"relationships": relationships.toMap(),
};
}
class DatumAttributes {
DatumAttributes({
this.slug,
this.name,
});
String slug;
String name;
factory DatumAttributes.fromMap(Map<String, dynamic> json) => DatumAttributes(
slug: json["slug"],
name: json["name"],
);
Map<String, dynamic> toMap() => {
"slug": slug,
"name": name,
};
}
class Relationships {
Relationships();
factory Relationships.fromMap(Map<String, dynamic> json) => Relationships(
);
Map<String, dynamic> toMap() => {
};
}
class Included {
Included({
this.id,
this.type,
this.attributes,
});
String id;
String type;
IncludedAttributes attributes;
factory Included.fromMap(Map<String, dynamic> json) => Included(
id: json["id"],
type: json["type"],
attributes: IncludedAttributes.fromMap(json["attributes"]),
);
Map<String, dynamic> toMap() => {
"id": id,
"type": type,
"attributes": attributes.toMap(),
};
}
class IncludedAttributes {
IncludedAttributes({
this.viewableType,
this.viewableId,
this.mobileImageStyles,
});
String viewableType;
int viewableId;
MobileImageStyles mobileImageStyles;
factory IncludedAttributes.fromMap(Map<String, dynamic> json) => IncludedAttributes(
viewableType: json["viewable_type"],
viewableId: json["viewable_id"],
mobileImageStyles: MobileImageStyles.fromMap(json["mobile_image_styles"]),
);
Map<String, dynamic> toMap() => {
"viewable_type": viewableType,
"viewable_id": viewableId,
"mobile_image_styles": mobileImageStyles.toMap(),
};
}
class MobileImageStyles {
MobileImageStyles({
this.mini,
this.small,
});
Mini mini;
Mini small;
factory MobileImageStyles.fromMap(Map<String, dynamic> json) => MobileImageStyles(
mini: Mini.fromMap(json["mini"]),
small: Mini.fromMap(json["small"]),
);
Map<String, dynamic> toMap() => {
"mini": mini.toMap(),
"small": small.toMap(),
};
}
class Mini {
Mini({
this.url,
this.size,
this.width,
this.height,
});
String url;
String size;
int width;
int height;
factory Mini.fromMap(Map<String, dynamic> json) => Mini(
url: json["url"],
size: json["size"],
width: json["width"],
height: json["height"],
);
Map<String, dynamic> toMap() => {
"url": url,
"size": size,
"width": width,
"height": height,
};
}