Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To parse this JSON data, do
- //
- // final currency = currencyFromJson(jsonString);
- import 'dart:convert';
- Currency currencyFromJson(String str) {
- final jsonData = json.decode(str);
- return Currency.fromJson(jsonData);
- }
- String currencyToJson(Currency data) {
- final dyn = data.toJson();
- return json.encode(dyn);
- }
- class Currency {
- int id;
- String name;
- String symbol;
- String slug;
- dynamic circulatingSupply;
- double totalSupply;
- dynamic maxSupply;
- String dateAdded;
- int numMarketPairs;
- List<dynamic> tags;
- Platform platform;
- int cmcRank;
- String lastUpdated;
- Quote quote;
- Currency({
- this.id,
- this.name,
- this.symbol,
- this.slug,
- this.circulatingSupply,
- this.totalSupply,
- this.maxSupply,
- this.dateAdded,
- this.numMarketPairs,
- this.tags,
- this.platform,
- this.cmcRank,
- this.lastUpdated,
- this.quote,
- });
- factory Currency.fromJson(Map<String, dynamic> json) => new Currency(
- id: json["id"],
- name: json["name"],
- symbol: json["symbol"],
- slug: json["slug"],
- circulatingSupply: json["circulating_supply"],
- totalSupply: json["total_supply"].toDouble(),
- maxSupply: json["max_supply"],
- dateAdded: json["date_added"],
- numMarketPairs: json["num_market_pairs"],
- tags: new List<dynamic>.from(json["tags"].map((x) => x)),
- platform: Platform.fromJson(json["platform"]),
- cmcRank: json["cmc_rank"],
- lastUpdated: json["last_updated"],
- quote: Quote.fromJson(json["quote"]),
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "name": name,
- "symbol": symbol,
- "slug": slug,
- "circulating_supply": circulatingSupply,
- "total_supply": totalSupply,
- "max_supply": maxSupply,
- "date_added": dateAdded,
- "num_market_pairs": numMarketPairs,
- "tags": new List<dynamic>.from(tags.map((x) => x)),
- "platform": platform.toJson(),
- "cmc_rank": cmcRank,
- "last_updated": lastUpdated,
- "quote": quote.toJson(),
- };
- }
- class Platform {
- int id;
- String name;
- String symbol;
- String slug;
- String tokenAddress;
- Platform({
- this.id,
- this.name,
- this.symbol,
- this.slug,
- this.tokenAddress,
- });
- factory Platform.fromJson(Map<String, dynamic> json) => new Platform(
- id: json["id"],
- name: json["name"],
- symbol: json["symbol"],
- slug: json["slug"],
- tokenAddress: json["token_address"],
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "name": name,
- "symbol": symbol,
- "slug": slug,
- "token_address": tokenAddress,
- };
- }
- class Quote {
- Usd usd;
- Quote({
- this.usd,
- });
- factory Quote.fromJson(Map<String, dynamic> json) => new Quote(
- usd: Usd.fromJson(json["USD"]),
- );
- Map<String, dynamic> toJson() => {
- "USD": usd.toJson(),
- };
- }
- class Usd {
- double price;
- int volume24H;
- double percentChange1H;
- double percentChange24H;
- double percentChange7D;
- int marketCap;
- String lastUpdated;
- Usd({
- this.price,
- this.volume24H,
- this.percentChange1H,
- this.percentChange24H,
- this.percentChange7D,
- this.marketCap,
- this.lastUpdated,
- });
- factory Usd.fromJson(Map<String, dynamic> json) => new Usd(
- price: json["price"].toDouble(),
- volume24H: json["volume_24h"],
- percentChange1H: json["percent_change_1h"].toDouble(),
- percentChange24H: json["percent_change_24h"].toDouble(),
- percentChange7D: json["percent_change_7d"].toDouble(),
- marketCap: json["market_cap"],
- lastUpdated: json["last_updated"],
- );
- Map<String, dynamic> toJson() => {
- "price": price,
- "volume_24h": volume24H,
- "percent_change_1h": percentChange1H,
- "percent_change_24h": percentChange24H,
- "percent_change_7d": percentChange7D,
- "market_cap": marketCap,
- "last_updated": lastUpdated,
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement