复杂模型解析求助
来源:12-3 首页大接口相关模型实现【Model层设计】
慕妹406553
2020-04-26
看了讲师的课程受益匪浅,试图照虎画猫,做个项目练练手。无奈卡在三层复杂json解析问题,一直解决不了。盼老师解惑。
json数据和model源码如下:
{
"code": 1,
"msg": "数据列表",
"page": 1,
"pagecount": 1,
"limit": "10",
"total": 1,
"list": [{
"vod_id": 77348,
"type_id": 7,
"type_id_1": 1,
"group_id": 0,
"vod_name": "胖子行动队",
"vod_sub": "",
"vod_en": "pangzixingdongdui",
"vod_status": 1,
"vod_letter": "P",
"vod_color": "",
"vod_tag": "胖子,行动队,行动,该片,讲述,两个,胖子,阴错阳差,组成,特别,行动队,行动,介入,一起,贩毒,案件,上演,了一,一场,啼笑皆非,特工,之旅,故事",
"vod_class": "喜剧",
"vod_pic": "upload\/vod\/20200422-1\/578d0cc0de547e65e2d0440a2c3fd23e.jpg",
"vod_pic_thumb": "",
"vod_pic_slide": "",
"vod_actor": "包贝尔,文章,李成敏,许君聪",
"vod_director": "包贝尔",
"vod_writer": "",
"vod_behind": "",
"vod_blurb": "该片讲述了两个胖子阴错阳差组成了特别行动队,介入一起贩毒案件中,上演了一场啼笑皆非的特工之旅的故事",
"vod_remarks": "蓝光",
"vod_pubdate": "",
"vod_total": 0,
"vod_serial": "0",
"vod_tv": "",
"vod_weekday": "",
"vod_area": "大陆",
"vod_lang": "",
"vod_year": "0",
"vod_version": "",
"vod_state": "",
"vod_author": "",
"vod_jumpurl": "",
"vod_tpl": "",
"vod_tpl_play": "",
"vod_tpl_down": "",
"vod_isend": 1,
"vod_lock": 0,
"vod_level": 0,
"vod_copyright": 0,
"vod_points": 0,
"vod_points_play": 0,
"vod_points_down": 0,
"vod_hits": 33,
"vod_hits_day": 1,
"vod_hits_week": 1,
"vod_hits_month": 1,
"vod_duration": "",
"vod_up": 681,
"vod_down": 204,
"vod_score": "1.0",
"vod_score_all": 558,
"vod_score_num": 558,
"vod_time": 1587398772,
"vod_time_add": 0,
"vod_time_hits": 1587539650,
"vod_time_make": 0,
"vod_trysee": 0,
"vod_douban_id": 0,
"vod_douban_score": "0.0",
"vod_reurl": "",
"vod_rel_vod": "",
"vod_rel_art": "",
"vod_pwd": "",
"vod_pwd_url": "",
"vod_pwd_play": "",
"vod_pwd_play_url": "",
"vod_pwd_down": "",
"vod_pwd_down_url": "",
"vod_content": "该片讲述了两个胖子阴错阳差组成了特别行动队,介入一起贩毒案件中,上演了一场啼笑皆非的特工之旅的故事",
"vod_play_from": "mgtv$$$sohu$$$qq$$$youku$$$qiyi$$$letv$$$m1905$$$migu",
"vod_play_server": "no$$$no$$$no$$$no$$$no$$$no$$$no$$$no",
"vod_play_note": "$$$$$$$$$$$$$$$$$$$$$",
"vod_play_url": "蓝光$https:\/\/www.mgtv.com\/b\/324942\/4784890.html$$$正片$http:\/\/tv.sohu.com\/item\/MTIxNzc4Nw==.html$$$高清$http:\/\/v.qq.com\/x\/cover\/hdavca20ujfapqy.html$$$高清$http:\/\/v.youku.com\/v_nextstage\/id_14b9a99b71614e1f9fae.html$$$高清$http:\/\/www.iqiyi.com\/v_19rr8u75c0.html$$$蓝光$http:\/\/www.le.com\/ptv\/vplay\/31515085.html$$$HD1080P$http:\/\/vip.1905.com\/play\/1345383.shtml$$$HD高清$https:\/\/www.miguvideo.com\/mgs\/msite\/prd\/detail.html?cid=650168133&channelid=10290002017",
"vod_down_from": "",
"vod_down_server": "",
"vod_down_note": "",
"vod_down_url": "",
"vod_plot": 0,
"vod_plot_name": "",
"vod_plot_detail": "",
"vod_play_list": {
"4": {
"sid": 4,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "youku",
"show": "优酷视频",
"des": "youku.com",
"target": "_blank",
"ps": "0",
"parse": "",
"sort": "618",
"tip": "跳转到优酷播放",
"id": "youku"
},
"server_info": null,
"from": "youku",
"url": "高清$http:\/\/v.youku.com\/v_nextstage\/id_14b9a99b71614e1f9fae.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "高清",
"url": "http:\/\/v.youku.com\/v_nextstage\/id_14b9a99b71614e1f9fae.html",
"from": "youku",
"nid": 1
}
}
},
"3": {
"sid": 3,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "qq",
"show": "腾讯视频",
"des": "v.qq.com",
"target": "_blank",
"ps": "0",
"parse": "",
"sort": "614",
"tip": "将跳转到腾讯视频播放",
"id": "qq"
},
"server_info": null,
"from": "qq",
"url": "高清$http:\/\/v.qq.com\/x\/cover\/hdavca20ujfapqy.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "高清",
"url": "http:\/\/v.qq.com\/x\/cover\/hdavca20ujfapqy.html",
"from": "qq",
"nid": 1
}
}
},
"2": {
"sid": 2,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "sohu",
"show": "搜狐视频",
"des": "v.sohu.com",
"target": "_blank",
"ps": "0",
"parse": "",
"sort": "613",
"tip": "将跳转到搜狐视频播放",
"id": "sohu"
},
"server_info": null,
"from": "sohu",
"url": "正片$http:\/\/tv.sohu.com\/item\/MTIxNzc4Nw==.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "正片",
"url": "http:\/\/tv.sohu.com\/item\/MTIxNzc4Nw==.html",
"from": "sohu",
"nid": 1
}
}
},
"5": {
"sid": 5,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "qiyi",
"show": "奇艺视频",
"des": "qiyi.com",
"target": "_blank",
"ps": "0",
"parse": "",
"sort": "611",
"tip": "无需安装任何插件",
"id": "qiyi"
},
"server_info": null,
"from": "qiyi",
"url": "高清$http:\/\/www.iqiyi.com\/v_19rr8u75c0.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "高清",
"url": "http:\/\/www.iqiyi.com\/v_19rr8u75c0.html",
"from": "qiyi",
"nid": 1
}
}
},
"6": {
"sid": 6,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "letv",
"show": "乐视视频",
"des": "letv.com",
"target": "_self",
"ps": "0",
"parse": "",
"sort": "610",
"tip": "无需安装任何插件",
"id": "letv"
},
"server_info": null,
"from": "letv",
"url": "蓝光$http:\/\/www.le.com\/ptv\/vplay\/31515085.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "蓝光",
"url": "http:\/\/www.le.com\/ptv\/vplay\/31515085.html",
"from": "letv",
"nid": 1
}
}
},
"1": {
"sid": 1,
"player_info": {
"status": "1",
"copyright_url": "1",
"from": "mgtv",
"show": "芒果tv",
"des": "mgtv.com",
"target": "_blank",
"ps": "0",
"parse": "",
"sort": "608",
"tip": "将跳转到芒果TV播放",
"id": "mgtv"
},
"server_info": null,
"from": "mgtv",
"url": "蓝光$https:\/\/www.mgtv.com\/b\/324942\/4784890.html",
"server": "no",
"note": "",
"url_count": 1,
"urls": {
"1": {
"name": "蓝光",
"url": "https:\/\/www.mgtv.com\/b\/324942\/4784890.html",
"from": "mgtv",
"nid": 1
}
}
}
}
}]
}
///视频详情页模型
//单个播放地址模型
class Url {
String name;
String url;
String from;
int nid;
Url({this.name, this.url, this.from, this.nid});
Url.fromJson(Map<String, dynamic> json) {
name = json['name'];
url = json['url'];
from = json['from'];
nid = json['nid'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['name'] = this.name;
data['url'] = this.url;
data['from'] = this.from;
data['nid'] = this.nid;
return data;
}
}
//播放地址组tips
class PlayerInfo {
String status;
String from;
String show;
String des;
String target;
String ps;
String parse;
String sort;
String tip;
String id;
PlayerInfo(
{this.status,
this.from,
this.show,
this.des,
this.target,
this.ps,
this.parse,
this.sort,
this.tip,
this.id});
PlayerInfo.fromJson(Map<String, dynamic> json) {
status = json['status'];
from = json['from'];
show = json['show'];
des = json['des'];
target = json['target'];
ps = json['ps'];
parse = json['parse'];
sort = json['sort'];
tip = json['tip'];
id = json['id'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['status'] = this.status;
data['from'] = this.from;
data['show'] = this.show;
data['des'] = this.des;
data['target'] = this.target;
data['ps'] = this.ps;
data['parse'] = this.parse;
data['sort'] = this.sort;
data['tip'] = this.tip;
data['id'] = this.id;
return data;
}
}
//播放或者下载地址组模型
class VodList {
String sid;
PlayerInfo playerInfo;
String serverInfo;
String from;
String url;
String server;
String note;
int urlCount;
Map<String, Url> urls;
VodList(
{this.sid,
this.playerInfo,
this.serverInfo,
this.from,
this.server,
this.note,
this.urlCount,
this.urls});
VodList.fromJson(Map<String, dynamic> json) {
sid = json['sid'];
playerInfo = PlayerInfo.fromJson(json['player_info']);
serverInfo = json['server_info'];
from = json['from'];
url = json['url'];
server = json['server'];
note = json['note'];
urlCount = json['url_count'];
var urlsListJson = json['urls'];
var urlsMap = [];
urlsListJson.forEach((k, v) {
urlsMap[k].add(Url.fromJson(v));
});
/*List<Url> urlslist = urlsListJson.map((i) => Url.fromJson(i)).toList();
urls = urlslist;*/
urls = urlsMap as Map;
}
}
//视频详情模型
class MovieDetailMac {
int vodId;
int typeId;
int typeId1;
int groupId;
String vodName;
String vodSub;
String vodEn;
int vodStatus;
String vodLetter;
String vodColor;
String vodTag;
String vodClass;
String vodPic;
String vodPicThumb;
String vodPicSlide;
String vodActor;
String vodDirector;
String vodWriter;
String vodBehind;
String vodBlurb;
String vodRemarks;
String vodPubdate;
int vodTotal;
String vodSerial;
String vodTv;
String vodWeekday;
String vodArea;
String vodLang;
String vodYear;
String vodVersion;
String vodState;
String vodAuthor;
String vodJumpurl;
String vodTpl;
String vodTplPlay;
String vodTplDown;
int vodIsend;
int vodLock;
int vodLevel;
int vodCopyright;
int vodPoints;
int vodPointsPlay;
int vodPointsDown;
int vodHits;
int vodHitsDay;
int vodHitsWeek;
int vodHitsMonth;
String vodDuration;
int vodUp;
int vodDown;
String vodScore;
int vodScoreAll;
int vodScoreNum;
int vodTime;
int vodTimeAdd;
int vodTimeHits;
int vodTimeMake;
int vodTrysee;
int vodDoubanId;
String vodDoubanScore;
String vodReurl;
String vodRelVod;
String vodRelArt;
String vodPwd;
String vodPwdUrl;
String vodPwdPlay;
String vodPwdPlayUrl;
String vodPwdDown;
String vodPwdDownUrl;
String vodContent;
String vodPlayFrom;
String vodPlayServer;
String vodPlayNote;
String vodPlayUrl;
String vodDownFrom;
String vodDownServer;
String vodDownNote;
String vodDownUrl;
int vodPlot;
String vodPlotName;
String vodPlotDetail;
List<VodList> vodDownList;
List<VodList> vodPlayList;
MovieDetailMac({
this.vodId,
this.typeId,
this.typeId1,
this.groupId,
this.vodName,
this.vodSub,
this.vodEn,
this.vodStatus,
this.vodLetter,
this.vodColor,
this.vodTag,
this.vodClass,
this.vodPic,
this.vodPicThumb,
this.vodPicSlide,
this.vodActor,
this.vodDirector,
this.vodWriter,
this.vodBehind,
this.vodBlurb,
this.vodRemarks,
this.vodPubdate,
this.vodTotal,
this.vodSerial,
this.vodTv,
this.vodWeekday,
this.vodArea,
this.vodLang,
this.vodYear,
this.vodVersion,
this.vodState,
this.vodAuthor,
this.vodJumpurl,
this.vodTpl,
this.vodTplPlay,
this.vodTplDown,
this.vodIsend,
this.vodLock,
this.vodLevel,
this.vodCopyright,
this.vodPoints,
this.vodPointsPlay,
this.vodPointsDown,
this.vodHits,
this.vodHitsDay,
this.vodHitsWeek,
this.vodHitsMonth,
this.vodDuration,
this.vodUp,
this.vodDown,
this.vodScore,
this.vodScoreAll,
this.vodScoreNum,
this.vodTime,
this.vodTimeAdd,
this.vodTimeHits,
this.vodTimeMake,
this.vodTrysee,
this.vodDoubanId,
this.vodDoubanScore,
this.vodReurl,
this.vodRelVod,
this.vodRelArt,
this.vodPwd,
this.vodPwdUrl,
this.vodPwdPlay,
this.vodPwdPlayUrl,
this.vodPwdDown,
this.vodPwdDownUrl,
this.vodContent,
this.vodPlayFrom,
this.vodPlayServer,
this.vodPlayNote,
this.vodPlayUrl,
this.vodDownFrom,
this.vodDownServer,
this.vodDownNote,
this.vodDownUrl,
this.vodPlot,
this.vodPlotName,
this.vodPlotDetail,
this.vodDownList,
this.vodPlayList,
});
MovieDetailMac.fromJson(Map<String, dynamic> json) {
vodId = json['vod_id'];
typeId = json['type_id'];
typeId1 = json['type_id_1'];
groupId = json['group_id'];
vodName = json['vod_name'];
vodSub = json['vod_sub'];
vodEn = json['vod_en'];
vodStatus = json['vod_status'];
vodLetter = json['vod_letter'];
vodColor = json['vod_color'];
vodTag = json['vod_tag'];
vodClass = json['vod_class'];
vodPic = json['vod_pic'];
vodPicThumb = json['vod_pic_thumb'];
vodPicSlide = json['vod_pic_slide'];
vodActor = json['vod_actor'];
vodDirector = json['vod_director'];
vodWriter = json['vod_writer'];
vodBehind = json['vod_behind'];
vodBlurb = json['vod_blurb'];
vodRemarks = json['vod_remarks'];
vodPubdate = json['vod_pubdate'];
vodTotal = json['vod_total'];
vodSerial = json['vod_serial'];
vodTv = json['vod_tv'];
vodWeekday = json['vod_weekday'];
vodArea = json['vod_area'];
vodLang = json['vod_lang'];
vodYear = json['vod_year'];
vodVersion = json['vod_version'];
vodState = json['vod_state'];
vodAuthor = json['vod_author'];
vodJumpurl = json['vod_jumpurl'];
vodTpl = json['vod_tpl'];
vodTplPlay = json['vod_tpl_play'];
vodTplDown = json['vod_tpl_down'];
vodIsend = json['vod_isend'];
vodLock = json['vod_lock'];
vodLevel = json['vod_level'];
vodCopyright = json['vod_copyright'];
vodPoints = json['vod_points'];
vodPointsPlay = json['vod_points_play'];
vodPointsDown = json['vod_points_down'];
vodHits = json['vod_hits'];
vodHitsDay = json['vod_hits_day'];
vodHitsWeek = json['vod_hits_week'];
vodHitsMonth = json['vod_hits_month'];
vodDuration = json['vod_duration'];
vodUp = json['vod_up'];
vodDown = json['vod_down'];
vodScore = json['vod_score'];
vodScoreAll = json['vod_score_all'];
vodScoreNum = json['vod_score_num'];
vodTime = json['vod_time'];
vodTimeAdd = json['vod_time_add'];
vodTimeHits = json['vod_time_hits'];
vodTimeMake = json['vod_time_make'];
vodTrysee = json['vod_trysee'];
vodDoubanId = json['vod_douban_id'];
vodDoubanScore = json['vod_douban_score'];
vodReurl = json['vod_reurl'];
vodRelVod = json['vod_rel_vod'];
vodRelArt = json['vod_rel_art'];
vodPwd = json['vod_pwd'];
vodPwdUrl = json['vod_pwd_url'];
vodPwdPlay = json['vod_pwd_play'];
vodPwdPlayUrl = json['vod_pwd_play_url'];
vodPwdDown = json['vod_pwd_down'];
vodPwdDownUrl = json['vod_pwd_down_url'];
vodContent = json['vod_content'];
vodPlayFrom = json['vod_play_from'];
vodPlayServer = json['vod_play_server'];
vodPlayNote = json['vod_play_note'];
vodPlayUrl = json['vod_play_url'];
vodDownFrom = json['vod_down_from'];
vodDownServer = json['vod_down_server'];
vodDownNote = json['vod_down_note'];
vodDownUrl = json['vod_down_url'];
vodPlot = json['vod_plot'];
vodPlotName = json['vod_plot_name'];
vodPlotDetail = json['vod_plot_detail'];
var vodDownListJson = json['vod_down_list'];
var vodPlayListJson = json['vod_play_list'];
print(vodDownListJson);
var vodDownListMap = [];
vodDownListJson.foreach((k, v) {
vodDownListMap[k].add(VodList.fromJson(v));
});
vodDownList = vodDownListMap;
var vodPlayListMap = [];
vodPlayListJson.foreach((k, v) {
vodPlayListMap[k].add(VodList.fromJson(v));
});
vodPlayList = vodPlayListMap;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['vod_id'] = this.vodId;
data['type_id'] = this.typeId;
data['type_id_1'] = this.typeId1;
data['group_id'] = this.groupId;
data['vod_name'] = this.vodName;
data['vod_sub'] = this.vodSub;
data['vod_en'] = this.vodEn;
data['vod_status'] = this.vodStatus;
data['vod_letter'] = this.vodLetter;
data['vod_color'] = this.vodColor;
data['vod_tag'] = this.vodTag;
data['vod_class'] = this.vodClass;
data['vod_pic'] = this.vodPic;
data['vod_pic_thumb'] = this.vodPicThumb;
data['vod_pic_slide'] = this.vodPicSlide;
data['vod_actor'] = this.vodActor;
data['vod_director'] = this.vodDirector;
data['vod_writer'] = this.vodWriter;
data['vod_behind'] = this.vodBehind;
data['vod_blurb'] = this.vodBlurb;
data['vod_remarks'] = this.vodRemarks;
data['vod_pubdate'] = this.vodPubdate;
data['vod_total'] = this.vodTotal;
data['vod_serial'] = this.vodSerial;
data['vod_tv'] = this.vodTv;
data['vod_weekday'] = this.vodWeekday;
data['vod_area'] = this.vodArea;
data['vod_lang'] = this.vodLang;
data['vod_year'] = this.vodYear;
data['vod_version'] = this.vodVersion;
data['vod_state'] = this.vodState;
data['vod_author'] = this.vodAuthor;
data['vod_jumpurl'] = this.vodJumpurl;
data['vod_tpl'] = this.vodTpl;
data['vod_tpl_play'] = this.vodTplPlay;
data['vod_tpl_down'] = this.vodTplDown;
data['vod_isend'] = this.vodIsend;
data['vod_lock'] = this.vodLock;
data['vod_level'] = this.vodLevel;
data['vod_copyright'] = this.vodCopyright;
data['vod_points'] = this.vodPoints;
data['vod_points_play'] = this.vodPointsPlay;
data['vod_points_down'] = this.vodPointsDown;
data['vod_hits'] = this.vodHits;
data['vod_hits_day'] = this.vodHitsDay;
data['vod_hits_week'] = this.vodHitsWeek;
data['vod_hits_month'] = this.vodHitsMonth;
data['vod_duration'] = this.vodDuration;
data['vod_up'] = this.vodUp;
data['vod_down'] = this.vodDown;
data['vod_score'] = this.vodScore;
data['vod_score_all'] = this.vodScoreAll;
data['vod_score_num'] = this.vodScoreNum;
data['vod_time'] = this.vodTime;
data['vod_time_add'] = this.vodTimeAdd;
data['vod_time_hits'] = this.vodTimeHits;
data['vod_time_make'] = this.vodTimeMake;
data['vod_trysee'] = this.vodTrysee;
data['vod_douban_id'] = this.vodDoubanId;
data['vod_douban_score'] = this.vodDoubanScore;
data['vod_reurl'] = this.vodReurl;
data['vod_rel_vod'] = this.vodRelVod;
data['vod_rel_art'] = this.vodRelArt;
data['vod_pwd'] = this.vodPwd;
data['vod_pwd_url'] = this.vodPwdUrl;
data['vod_pwd_play'] = this.vodPwdPlay;
data['vod_pwd_play_url'] = this.vodPwdPlayUrl;
data['vod_pwd_down'] = this.vodPwdDown;
data['vod_pwd_down_url'] = this.vodPwdDownUrl;
data['vod_content'] = this.vodContent;
data['vod_play_from'] = this.vodPlayFrom;
data['vod_play_server'] = this.vodPlayServer;
data['vod_play_note'] = this.vodPlayNote;
data['vod_play_url'] = this.vodPlayUrl;
data['vod_down_from'] = this.vodDownFrom;
data['vod_down_server'] = this.vodDownServer;
data['vod_down_note'] = this.vodDownNote;
data['vod_down_url'] = this.vodDownUrl;
data['vod_plot'] = this.vodPlot;
data['vod_plot_name'] = this.vodPlotName;
data['vod_plot_detail'] = this.vodPlotDetail;
data['vodDownList'] = this.vodDownList;
data['vodPlayList'] = this.vodPlayList;
return data;
}
}
重点在:vodDownListJson.foreach((k, v) { vodDownListMap[k].add(VodList.fromJson(v)); }); vodDownList = vodDownListMap; var vodPlayListMap = []; vodPlayListJson.foreach((k, v) { vodPlayListMap[k].add(VodList.fromJson(v)); }); vodPlayList = vodPlayListMap; }
一直无法获取解析数据。
写回答
1回答
-
CrazyCodeBoy
2020-04-27
用工具转换下:https://www.devio.org/io/tools/json-to-dart/
然后在手动修改。00
相似问题