Example #1
0
 private Article[] Json2Articles(string json)
 {
     string[] items = json.Split(new string[] { "},{" }, StringSplitOptions.None);
     if (!items[0].Contains("\"id\""))
     {
         return new Article[0];
     }
     var list = new Article[items.Length];
     for (int i = 0; i < items.Length; i++)
     {
         list[i] = new Article()
         {
             Id = GetValue("id", items[i]).ToInt(),
             Title = GetValue("title", items[i]),
             CreateAt = GetValue("create_at", items[i]).ToDateTime(),
             ViewCount = GetValue("view_count", items[i]).ToInt(),
             CommentCount = GetValue("comment_count", items[i]).ToInt(),
             CommentAllowed = GetValue("comment_allowed", items[i]).ToBool(),
             Type = GetValue("type", items[i]),
             Channel = GetValue("channel", items[i]).ToInt(),
             Digg = GetValue("digg", items[i]).ToInt(),
             Bury = GetValue("bury", items[i]).ToInt(),
             Description = GetValue("description", items[i]),
             Url = GetValue("url", items[i])
         };
     }
     return list;
 }
Example #2
0
        public bool SaveArticle(ref Article entity)
        {
            string data = string.Format("id={0}&title={1}&type={2}&description={3}&content={4}&categories={5}&tags={6}&ip={7}"
                , entity.Id, entity.Title.UrlEncode(), entity.Type.UrlEncode()
                , entity.Description.UrlEncode(), entity.Content.UrlEncode()
                , string.Join(",", entity.Categories).UrlEncode()
                , string.Join(",", entity.Tags).UrlEncode()
                , clientIP
                );
            string json = Post("blog/savearticle", data);
            entity.Id = GetValue("id", json).ToInt();
            entity.Url = GetValue("url", json);

            return entity.Id > 0;
        }