推荐使用Json to Dart 然后item.images[0].src
class Item {
int id;
String name;
String slug;
String permalink;
String dateCreated;
String dateCreatedGmt;
String dateModified;
String dateModifiedGmt;
String type;
String status;
bool featured;
String catalogVisibility;
String description;
String shortDescription;
String sku;
String price;
String regularPrice;
String salePrice;
String weight;
Dimensions dimensions;
List<Categories> categories;
List<Null> tags;
List<Images> images;
Item(
{this.id,
this.name,
this.slug,
this.permalink,
this.dateCreated,
this.dateCreatedGmt,
this.dateModified,
this.dateModifiedGmt,
this.type,
this.status,
this.featured,
this.catalogVisibility,
this.description,
this.shortDescription,
this.sku,
this.price,
this.regularPrice,
this.salePrice,
this.weight,
this.dimensions,
this.categories,
this.tags,
this.images});
Item.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
slug = json['slug'];
permalink = json['permalink'];
dateCreated = json['date_created'];
dateCreatedGmt = json['date_created_gmt'];
dateModified = json['date_modified'];
dateModifiedGmt = json['date_modified_gmt'];
type = json['type'];
status = json['status'];
featured = json['featured'];
catalogVisibility = json['catalog_visibility'];
description = json['description'];
shortDescription = json['short_description'];
sku = json['sku'];
price = json['price'];
regularPrice = json['regular_price'];
salePrice = json['sale_price'];
weight = json['weight'];
dimensions = json['dimensions'] != null
? new Dimensions.fromJson(json['dimensions'])
: null;
if (json['categories'] != null) {
categories = new List<Categories>();
json['categories'].forEach((v) {
categories.add(new Categories.fromJson(v));
});
}
if (json['tags'] != null) {
tags = new List<Null>();
json['tags'].forEach((v) {
tags.add(new Null.fromJson(v));
});
}
if (json['images'] != null) {
images = new List<Images>();
json['images'].forEach((v) {
images.add(new Images.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
data['slug'] = this.slug;
data['permalink'] = this.permalink;
data['date_created'] = this.dateCreated;
data['date_created_gmt'] = this.dateCreatedGmt;
data['date_modified'] = this.dateModified;
data['date_modified_gmt'] = this.dateModifiedGmt;
data['type'] = this.type;
data['status'] = this.status;
data['featured'] = this.featured;
data['catalog_visibility'] = this.catalogVisibility;
data['description'] = this.description;
data['short_description'] = this.shortDescription;
data['sku'] = this.sku;
data['price'] = this.price;
data['regular_price'] = this.regularPrice;
data['sale_price'] = this.salePrice;
data['weight'] = this.weight;
if (this.dimensions != null) {
data['dimensions'] = this.dimensions.toJson();
}
if (this.categories != null) {
data['categories'] = this.categories.map((v) => v.toJson()).toList();
}
if (this.tags != null) {
data['tags'] = this.tags.map((v) => v.toJson()).toList();
}
if (this.images != null) {
data['images'] = this.images.map((v) => v.toJson()).toList();
}
return data;
}
}
class Dimensions {
String length;
String width;
String height;
Dimensions({this.length, this.width, this.height});
Dimensions.fromJson(Map<String, dynamic> json) {
length = json['length'];
width = json['width'];
height = json['height'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['length'] = this.length;
data['width'] = this.width;
data['height'] = this.height;
return data;
}
}
class Categories {
int id;
String name;
String slug;
Categories({this.id, this.name, this.slug});
Categories.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
slug = json['slug'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
data['slug'] = this.slug;
return data;
}
}
class Images {
int id;
String src;
String name;
String alt;
Images({this.id, this.src, this.name, this.alt});
Images.fromJson(Map<String, dynamic> json) {
id = json['id'];
src = json['src'];
name = json['name'];
alt = json['alt'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['src'] = this.src;
data['name'] = this.name;
data['alt'] = this.alt;
return data;
}
}