Advertisement
Guest User

Manual json deserialization in dart

a guest
Dec 9th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.80 KB | None | 0 0
  1. class Content {
  2. final String title;
  3. final String description;
  4. final String video_url;
  5. final String video_title;
  6.  
  7. Content({this.title,this.description,this.video_url,this.video_title});
  8. factory Content.fromJson(Map<String dynamic> json){
  9.     return Content (
  10.         title:json['title']??'',
  11.         description:json['description']??'',
  12.         video_url:json['video_url']??'',
  13.         video_title:json['video_title']??'',
  14.         );
  15.     }
  16. }
  17.  
  18. class Course {
  19. final String image_url;
  20. final String name;
  21. final List<Content> contents;
  22. Course({this.image_url,this.name,this.contents});
  23.  
  24. factory Course.fromJson(Map<String dynamic> json){
  25.     return Content (
  26.         name:json['name']??'',
  27.         image_url:json['image_url']??'',
  28.         contents:json['contents']?json['contents'].map((c){ return Content.fromJson(c);}).toList() :[],
  29.         );
  30.     }
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement