//------------------------------ add 增加置顶的帖子------------------------------------------------------------------- public static String MergeData(String json, List <ForumTopic> newTopics) { List <StickyTopic> stickyList = GetTopics(json); List <StickyTopic> results = mergeData(stickyList, newTopics); return(SimpleJsonString.ConvertList(results)); }
public static String GetSubCatsJson() { List <ViewCat> subcats = GetSubCatsForSelect(); String jsons = SimpleJsonString.ConvertList(subcats); return(jsons); }
public static String MoveDown(String json, int topicId) { List <StickyTopic> topics = GetTopics(json); StickyTopic t = getById(topics, topicId); SortUtil <StickyTopic> s = new SortUtil <StickyTopic>(t, topics); s.MoveDown(); return(SimpleJsonString.ConvertList(s.GetOrderedList())); }
//public Feed GetByIdWithComments( int id ) { // Feed feed = GetById( id ); // List<FeedComment> comments = FeedComment.find( "RootId="+id + " order by Id" ).list(); // feed.setComments( comments ); // return feed; //} //----------------------------------------------- 开放方法 -------------------------------------------------------------------- public virtual TemplateBundle registerTemplateBundle(List <OneLineStoryTemplate> oneLineStoryTemplates, List <ShortStoryTemplate> shortStoryTemplates, List <ActionLink> actionLinks) { TemplateBundle t = new TemplateBundle(); t.OneLineStoryTemplatesStr = SimpleJsonString.ConvertList(oneLineStoryTemplates); t.ShortStoryTemplatesStr = SimpleJsonString.ConvertList(shortStoryTemplates); t.ActionLinksStr = SimpleJsonString.ConvertList(actionLinks); db.insert(t); return(t); }
public void testNotSerialize() { TJPost x = new TJPost { Id = 8, Title = "标题1", CategoryId = 99, Info = "信息2", Description = "描述3" }; // NotSerialize 不会序列化,但NotSave会被序列化 String strJson = Json.ToString(x); Console.WriteLine(strJson); Assert.AreEqual("{ \"Id\":8, \"Title\":\"标题1\", \"CategoryId\":99, \"Description\":\"描述3\" }", strJson); // 让NotSave也不会序列化 strJson = SimpleJsonString.ConvertObject(x, true); Console.WriteLine(strJson); // 注意:SimpleJsonString模式下name没有引号 Assert.AreEqual("{ Id:8, Title:\"标题1\", CategoryId:99 }", strJson); TJPost x2 = new TJPost { Id = 81, Title = "标题11", CategoryId = 991, Info = "信息21", Description = "描述31" }; List <TJPost> list = new List <TJPost>(); list.Add(x); list.Add(x2); // MemeoryDB 在序列化的时候,NotSerialize等效于NotSave,相关属性都会忽略掉 // 对于MemeoryDB,建议只使用NotSave;因为在Json.ToString显示的时候,此属性还可以显示出来 // 如果MemeoryDB中使用NotSerialize,不但不会保存,也无法Json.ToString显示。 // NotSerialize主要用于ObjectBase模型,或者其他实体对象,方便Json.ToString strJson = SimpleJsonString.ConvertList(list, true); Console.WriteLine(strJson); String str = @"[ { Id:8, Title:""标题1"", CategoryId:99 }, { Id:81, Title:""标题11"", CategoryId:991 } ]"; Assert.AreEqual(str, strJson); }
private static void Serialize( Type t, IList list ) { String target = SimpleJsonString.ConvertList( list ); if (strUtil.IsNullOrEmpty( target )) return; String absolutePath = getCachePath( t ); lock (objLock) { String dir = Path.GetDirectoryName( absolutePath ); if (Directory.Exists( dir ) == false) { Directory.CreateDirectory( dir ); } wojilu.IO.File.Write( absolutePath, target ); } }
private static void Serialize(Type t, IList list) { String target = SimpleJsonString.ConvertList(list); if (strUtil.IsNullOrEmpty(target)) { return; } String absolutePath = getCachePath(t); lock (objLock) { System.IO.FileEx.Write(absolutePath, target); } }
public void SaveUpload() { HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { errors.Join(result); run(UploadForm); return; } AttachmentTemp uploadFile = savePostData(postedFile, result); // 返回数据给主页面 set("objFile", SimpleJsonString.ConvertObject(uploadFile)); set("deleteLink", to(DeleteTempAttachment)); }
public void SaveFlashUpload() { HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { errors.Join(result); echoError(); return; } AttachmentTemp uploadFile = savePostData(postedFile, result); // 返回json给主页面 String json = "{deleteLink:'" + to(DeleteTempAttachment) + "', photo:" + SimpleJsonString.ConvertObject(uploadFile) + "}"; echoText(json); }
public void SaveFlashUpload() { int boardId = ctx.GetInt("boardId"); HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { logger.Error(result.ErrorsText); errors.Join(result); echoError(); return; } AttachmentTemp uploadFile = savePostData(postedFile, result); // 返回json给主页面 String photoJson = SimpleJsonString.ConvertObject(uploadFile.GetJsonObject()); String json = "{\"deleteLink\":\"" + to(DeleteTempAttachment) + "?boardId=" + boardId + "\", \"photo\":" + photoJson + "}"; echoText(json); }
public void testSubObjects() { AdminMenu m = new AdminMenu { Id = "3", Name = "新闻", Url = "/abc.aspx" }; String str = SimpleJsonString.ConvertObject(m); Console.WriteLine(str); AdminMenuGroup g = new AdminMenuGroup(); g.Id = "118"; g.Name = "菜单组"; g.AdminMenus = new List <AdminMenu>(); g.AdminMenus.Add(m); //String subStr = JSON.ObjectToJSON( g ); String subStr = JsonString.Convert(g); Console.WriteLine(subStr); }
public void ObjectsToString() { IList results = new ArrayList(); results.Add(getPhoneList()); results.Add(getPhoneList()); results.Add(getPhoneList()); results.Add(getPhoneList()); string strJson = SimpleJsonString.ConvertList(results); Console.WriteLine(strJson); string result = @" [ { Id:0, Name:""新闻大事690501468"", Weight:0, Owner:""2"" }, { Id:0, Name:""新闻大事690501468"", Weight:0, Owner:""2"" }, { Id:0, Name:""新闻大事690501468"", Weight:0, Owner:""2"" }, { Id:0, Name:""新闻大事690501468"", Weight:0, Owner:""2"" } ] "; Assert.AreEqual(result.Trim(), strJson.Trim()); }
/// <summary> /// 将简单对象列表转换成 json 字符串,用于存储。对象之间换行,对象内部不换行。 /// </summary> /// <param name="list"></param> /// <returns></returns> public static String ToStringList(IList list) { return(SimpleJsonString.ConvertList(list)); }