Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // To parse this JSON data, do
  2. //
  3. // final currency = currencyFromJson(jsonString);
  4.  
  5. import 'dart:convert';
  6.  
  7. Currency currencyFromJson(String str) {
  8. final jsonData = json.decode(str);
  9. return Currency.fromJson(jsonData);
  10. }
  11.  
  12. String currencyToJson(Currency data) {
  13. final dyn = data.toJson();
  14. return json.encode(dyn);
  15. }
  16.  
  17. class Currency {
  18. int id;
  19. String name;
  20. String symbol;
  21. String slug;
  22. dynamic circulatingSupply;
  23. double totalSupply;
  24. dynamic maxSupply;
  25. String dateAdded;
  26. int numMarketPairs;
  27. List<dynamic> tags;
  28. Platform platform;
  29. int cmcRank;
  30. String lastUpdated;
  31. Quote quote;
  32.  
  33. Currency({
  34. this.id,
  35. this.name,
  36. this.symbol,
  37. this.slug,
  38. this.circulatingSupply,
  39. this.totalSupply,
  40. this.maxSupply,
  41. this.dateAdded,
  42. this.numMarketPairs,
  43. this.tags,
  44. this.platform,
  45. this.cmcRank,
  46. this.lastUpdated,
  47. this.quote,
  48. });
  49.  
  50. factory Currency.fromJson(Map<String, dynamic> json) => new Currency(
  51. id: json["id"],
  52. name: json["name"],
  53. symbol: json["symbol"],
  54. slug: json["slug"],
  55. circulatingSupply: json["circulating_supply"],
  56. totalSupply: json["total_supply"].toDouble(),
  57. maxSupply: json["max_supply"],
  58. dateAdded: json["date_added"],
  59. numMarketPairs: json["num_market_pairs"],
  60. tags: new List<dynamic>.from(json["tags"].map((x) => x)),
  61. platform: Platform.fromJson(json["platform"]),
  62. cmcRank: json["cmc_rank"],
  63. lastUpdated: json["last_updated"],
  64. quote: Quote.fromJson(json["quote"]),
  65. );
  66.  
  67. Map<String, dynamic> toJson() => {
  68. "id": id,
  69. "name": name,
  70. "symbol": symbol,
  71. "slug": slug,
  72. "circulating_supply": circulatingSupply,
  73. "total_supply": totalSupply,
  74. "max_supply": maxSupply,
  75. "date_added": dateAdded,
  76. "num_market_pairs": numMarketPairs,
  77. "tags": new List<dynamic>.from(tags.map((x) => x)),
  78. "platform": platform.toJson(),
  79. "cmc_rank": cmcRank,
  80. "last_updated": lastUpdated,
  81. "quote": quote.toJson(),
  82. };
  83. }
  84.  
  85. class Platform {
  86. int id;
  87. String name;
  88. String symbol;
  89. String slug;
  90. String tokenAddress;
  91.  
  92. Platform({
  93. this.id,
  94. this.name,
  95. this.symbol,
  96. this.slug,
  97. this.tokenAddress,
  98. });
  99.  
  100. factory Platform.fromJson(Map<String, dynamic> json) => new Platform(
  101. id: json["id"],
  102. name: json["name"],
  103. symbol: json["symbol"],
  104. slug: json["slug"],
  105. tokenAddress: json["token_address"],
  106. );
  107.  
  108. Map<String, dynamic> toJson() => {
  109. "id": id,
  110. "name": name,
  111. "symbol": symbol,
  112. "slug": slug,
  113. "token_address": tokenAddress,
  114. };
  115. }
  116.  
  117. class Quote {
  118. Usd usd;
  119.  
  120. Quote({
  121. this.usd,
  122. });
  123.  
  124. factory Quote.fromJson(Map<String, dynamic> json) => new Quote(
  125. usd: Usd.fromJson(json["USD"]),
  126. );
  127.  
  128. Map<String, dynamic> toJson() => {
  129. "USD": usd.toJson(),
  130. };
  131. }
  132.  
  133. class Usd {
  134. double price;
  135. int volume24H;
  136. double percentChange1H;
  137. double percentChange24H;
  138. double percentChange7D;
  139. int marketCap;
  140. String lastUpdated;
  141.  
  142. Usd({
  143. this.price,
  144. this.volume24H,
  145. this.percentChange1H,
  146. this.percentChange24H,
  147. this.percentChange7D,
  148. this.marketCap,
  149. this.lastUpdated,
  150. });
  151.  
  152. factory Usd.fromJson(Map<String, dynamic> json) => new Usd(
  153. price: json["price"].toDouble(),
  154. volume24H: json["volume_24h"],
  155. percentChange1H: json["percent_change_1h"].toDouble(),
  156. percentChange24H: json["percent_change_24h"].toDouble(),
  157. percentChange7D: json["percent_change_7d"].toDouble(),
  158. marketCap: json["market_cap"],
  159. lastUpdated: json["last_updated"],
  160. );
  161.  
  162. Map<String, dynamic> toJson() => {
  163. "price": price,
  164. "volume_24h": volume24H,
  165. "percent_change_1h": percentChange1H,
  166. "percent_change_24h": percentChange24H,
  167. "percent_change_7d": percentChange7D,
  168. "market_cap": marketCap,
  169. "last_updated": lastUpdated,
  170. };
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement