예제 #1
0
            /// <summary>
            /// 递归调用,用来转换Children内的Directory和Url
            /// </summary>
            /// <param name="array"></param>
            /// <returns></returns>
            List <BaseBookMarkInfo> GetInfo(JArray array)
            {
                List <BaseBookMarkInfo> lists = new List <BaseBookMarkInfo>();

                foreach (var item in array)
                {
                    if (item.Value <string>("type") == "url")
                    {
                        lists.Add(item.ToObject <BookMarkUrl>());
                    }
                    else
                    {
                        BookMarkDirectory bookMarkDirectory = new BookMarkDirectory()
                        {
                            DateAdded    = item.Value <string>("date_added").EdgeTimeToDateTime(),
                            Guid         = new Guid(item.Value <string>("guid")),
                            ID           = item.Value <uint>("id"),
                            Name         = item.Value <string>("name"),
                            Source       = item.Value <string>("source"),
                            Type         = item.Value <string>("type").ConvertToBookMarkType(),
                            DateModified = item.Value <string>("date_modified").EdgeTimeToDateTime(),
                            Children     = GetInfo(item.Value <JArray>("children")) //这里进行递归
                        };
                        lists.Add(bookMarkDirectory);
                    }
                }
                return(lists);
            }
예제 #2
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                var obj = serializer.Deserialize <JObject>(reader);
                BookMarkDirectory bookMarkDirectory = new BookMarkDirectory()
                {
                    DateAdded    = obj.Value <string>("date_added").EdgeTimeToDateTime(),
                    Guid         = new Guid(obj.Value <string>("guid")),
                    ID           = obj.Value <uint>("id"),
                    Name         = obj.Value <string>("name"),
                    Source       = obj.Value <string>("source"),
                    Type         = obj.Value <string>("type").ConvertToBookMarkType(),
                    DateModified = obj.Value <string>("date_modified").EdgeTimeToDateTime(),
                    Children     = GetInfo(obj.Value <JArray>("children"))
                };

                return(bookMarkDirectory);
            }