Skip to content

Instantly share code, notes, and snippets.

@Jahidul007
Created November 18, 2021 12:41
Show Gist options
  • Save Jahidul007/98e5ea1107fb9dca0bb7809f558776d4 to your computer and use it in GitHub Desktop.
Save Jahidul007/98e5ea1107fb9dca0bb7809f558776d4 to your computer and use it in GitHub Desktop.
import 'dart:convert';
void main() {
var response = [{
"id": 56012,
"name": "a name",
"slug": "a slug",
"description": "<p>آب آشامیدنی پیورلایف 1/5 لیتری نستله</p>\n",
"regular_price": "45000",
"sale_price": "45000",
"tags": [],
},
];
List<ProductModel> items=[];
response.forEach((e){
items.add(ProductModel.fromJson(e));
});
items.forEach((r){
print(r.description);
});
}
class ProductModel {
int id;
String name;
String slug;
String description;
String regularPrice;
String salePrice;
ProductModel(
{this.id,
this.name,
this.slug,
this.description,
this.regularPrice,
this.salePrice});
ProductModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
slug = json['slug'];
description = json['description'];
regularPrice = json['regular_price'];
salePrice = json['sale_price'];
}
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['description'] = this.description;
data['regular_price'] = this.regularPrice;
data['sale_price'] = this.salePrice;
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment