/// <summary> /// 根据json保存文章全文并下载图片 /// </summary> /// <param name="json"></param> /// <returns></returns> public Article.Model.Article getModelFromJson(string json) { if ((!json.Contains("该稿件未审核")) || json == "") { JObject jsonObj = JObject.Parse(json); JObject data = ((JObject)jsonObj["data"]); JObject tempo = ((JObject)data["fullArticle"]); Article.Model.Article article = new Article.Model.Article(); article.setChannelId(tempo["channelId"].ToString()); article.setComments(tempo["comments"].ToString()); article.setContentId(tempo["contentId"].ToString()); article.setCover(tempo["cover"].ToString()); article.setDescription(ReplaceHtmlTag(tempo["description"].ToString())); article.setIsArticle(tempo["isArticle"].ToString()); article.setIsRecommend(tempo["isRecommend"].ToString()); article.setReleaseDate(tempo["releaseDate"].ToString()); article.setStows(tempo["stows"].ToString()); article.setTitle(tempo["title"].ToString()); article.setToplevel(tempo["toplevel"].ToString()); article.setTxt(ReplaceHtmlTag(tempo["txt"].ToString())); JObject user = ((JObject)tempo["user"]); article.setUser(user["userId"].ToString()); article.setViewOnly(tempo["viewOnly"].ToString()); article.setViews(tempo["views"].ToString()); SavePostImg(GetHtmlImageUrlList(tempo["txt"].ToString()), article.getContentId()); getUserByArticle(json); return(article); } else { return(null); } }
/// <summary> /// 根据页码获取文章列表 /// </summary> /// <param name="pageNo"></param> /// <returns></returns> public List <Article.Model.Article> getArticleList(int pageNo) { List <Article.Model.Article> articleList = new List <Model.Article>(); WebUtil util = new WebUtil(); //获取该页中所有的文章编号 string articleNoList = util.GetArticleList(20, pageNo); if (articleNoList != "") { JObject jsonObj = JObject.Parse(articleNoList); string list = ((JObject)((JObject)jsonObj["data"])["page"])["list"].ToString(); JArray alist = JArray.Parse(list); for (int i = 0; i < alist.Count; ++i) //遍历JArray { Article.Model.Article article = new Article.Model.Article(); JObject tempo = JObject.Parse(alist[i].ToString()); article.setChannelId(tempo["channelId"].ToString()); article.setComments(tempo["comments"].ToString()); article.setContentId(tempo["contentId"].ToString()); article.setCover(tempo["cover"].ToString()); article.setDescription(tempo["description"].ToString()); article.setIsArticle(tempo["isArticle"].ToString()); article.setIsRecommend(tempo["isRecommend"].ToString()); article.setReleaseDate(tempo["releaseDate"].ToString()); article.setStows(tempo["stows"].ToString()); article.setTitle(tempo["title"].ToString()); article.setToplevel(tempo["toplevel"].ToString()); article.setTxt(tempo["description"].ToString()); article.setUser(tempo["user"].ToString()); article.setViewOnly(tempo["viewOnly"].ToString()); article.setViews(tempo["views"].ToString()); getCommentByArticle(article); articleList.Add(article); } } return(articleList); }