当前位置: 首页>>代码示例>>C#>>正文


C# System.Web.Script.Serialization.JavaScriptSerializer.Serialize方法代码示例

本文整理汇总了C#中System.Web.Script.Serialization.JavaScriptSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# System.Web.Script.Serialization.JavaScriptSerializer.Serialize方法的具体用法?C# System.Web.Script.Serialization.JavaScriptSerializer.Serialize怎么用?C# System.Web.Script.Serialization.JavaScriptSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Script.Serialization.JavaScriptSerializer的用法示例。


在下文中一共展示了System.Web.Script.Serialization.JavaScriptSerializer.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JsonHelper

 private static string JsonHelper(IEnumerable<Data> expected, IEnumerable<ResponseData> defaultGet, out string actualJson)
 {
     var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     var expectedJson = serializer.Serialize(expected);
     actualJson = serializer.Serialize(defaultGet);
     return expectedJson;
 }
开发者ID:joyjeet,项目名称:ServerTrack,代码行数:7,代码来源:DataControllerTest.cs

示例2: MonthWisePlanAndActual

 public ActionResult MonthWisePlanAndActual(IEnumerable<Target> targets)
 {
     var groupedTargetMonth = targets.GroupBy(x => x.Month);
     BarTargetModels model = new BarTargetModels();
     model.Models = groupedTargetMonth.Select(
         x => new BarTargetModel {
             Month = x.Key, T1 = x.Sum(y => { return y.T1.HasValue ? y.T1.Value : 0; }), T2 = x.Sum(y => {
                 return
                     y
                         .
                         T2
                         .
                         HasValue
                         ? y
                               .
                               T2
                               .
                               Value
                         : 0;
             }), Actual = x.Sum(y => { return y.Actual.HasValue ? y.Actual.Value : 0; })
         }).ToList();
     var months = model.Models.Select(x => x.Month.Substring(0, 3));
     var actuals = model.Models.Select(x => x.Actual);
     var t1 = model.Models.Select(x => x.T1);
     var t2 = model.Models.Select(x => x.T2);
     var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     ViewBag.months = serializer.Serialize(months);
     ViewBag.actuals = serializer.Serialize(actuals);
     ViewBag.t1 = serializer.Serialize(t1);
     ViewBag.t2 = serializer.Serialize(t2);
     return PartialView("MonthWisePlanAndActual");
 }
开发者ID:akhilrex,项目名称:DMP_New,代码行数:32,代码来源:ReportingController.cs

示例3: ChangeNodeStatusToHistory

        public String ChangeNodeStatusToHistory(int idNote)
        {
            String statusMessage;
            String jsonString;
            var scriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            String login = User.Identity.Name;

            User user = unitOfWork.UserRepository.Get().Where(a => a.Login.Trim() == login).FirstOrDefault();

            var note = unitOfWork.NoteRepository.GetByID(idNote);

            if (note.IdUser == user.Id)
            {
                note.IdNoteStatus = 1;
                unitOfWork.NoteRepository.Update(note);
                unitOfWork.Save();

                statusMessage = "success";

                jsonString = scriptSerializer.Serialize(new { status = statusMessage });
                return jsonString;
            }

            statusMessage = "fail";

            jsonString = scriptSerializer.Serialize(new { status = statusMessage });
            return jsonString;
        }
开发者ID:Hixon10,项目名称:Notes,代码行数:29,代码来源:NoteController.cs

示例4: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string resultStr = string.Empty;

            string repoApplyStr = context.Request.Form["repoApply"];
            if (string.IsNullOrEmpty(repoApplyStr))
            {
                context.Response.Write("赎回申请单信息不能为空");
                context.Response.End();
            }
            string rowsStr = context.Request.Form["rows"];
            if (string.IsNullOrEmpty(rowsStr))
            {
                context.Response.Write("明细信息不能为空");
                context.Response.End();
            }

            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

            try
            {
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                NFMT.Finance.Model.RepoApply repoApply = serializer.Deserialize<NFMT.Finance.Model.RepoApply>(repoApplyStr);
                List<NFMT.Finance.Model.RepoApplyDetail> details = serializer.Deserialize<List<NFMT.Finance.Model.RepoApplyDetail>>(rowsStr);
                if (repoApply == null || details == null || !details.Any())
                {
                    context.Response.Write("信息错误");
                    context.Response.End();
                }

                decimal sumNetAmount = 0;
                int sumHands = 0;
                foreach (NFMT.Finance.Model.RepoApplyDetail detail in details)
                {
                    sumNetAmount += detail.NetAmount;
                    sumHands += detail.Hands;
                }

                repoApply.SumNetAmount = sumNetAmount;
                repoApply.SumHands = sumHands;

                string userJson = serializer.Serialize(user);
                string repoApplyJson = serializer.Serialize(repoApply);

                FinanceService.FinService service = new FinanceService.FinService();
                resultStr = service.FinRepoApplyUpdate(userJson, repoApplyJson, rowsStr);
            }
            catch (Exception e)
            {
                result.ResultStatus = -1;
                result.Message = e.Message;
            }

            context.Response.Write(resultStr);
            context.Response.End();
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:58,代码来源:FinRepoApplyUpdateHandler.ashx.cs

示例5: AreEqual

        public static void AreEqual(object expected, object actual)
        {
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            var actualSerialized = serializer.Serialize(actual);
            var expectedSerialized = serializer.Serialize(expected);

            Assert.AreEqual(expectedSerialized, actualSerialized);
        }
开发者ID:JogoShugh,项目名称:ModularAspNetMvc,代码行数:9,代码来源:SerializedStringAssert.cs

示例6: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            context.Response.ContentType = "text/plain";

            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

            if (string.IsNullOrEmpty(context.Request.Form["source"]))
            {
                result.Message = "数据源为空";
                result.ResultStatus = -1;
                context.Response.Write(serializer.Serialize(result));
                context.Response.End();
            }

            bool isPass = false;
            if (string.IsNullOrEmpty(context.Request.Form["ispass"]) || !bool.TryParse(context.Request.Form["ispass"], out isPass))
            {
                result.Message = "审核结果错误";
                result.ResultStatus = -1;
                context.Response.Write(serializer.Serialize(result));
                context.Response.End();
            }

            try
            {
                string jsonData = context.Request.Form["source"];
                var obj = serializer.Deserialize<NFMT.WorkFlow.Model.DataSource>(jsonData);

                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    NFMT.Contract.BLL.ContractBLL bll = new NFMT.Contract.BLL.ContractBLL();
                    result = bll.ContractInAudit(user, obj, isPass);
                    if (result.ResultStatus == 0)
                    {
                        int contractId = (int)result.ReturnValue;
                        int subId = result.AffectCount;

                        NFMT.WareHouse.BLL.StockLogBLL stockLogBLL = new NFMT.WareHouse.BLL.StockLogBLL();
                        result = stockLogBLL.ContractInAuditStockLogOperate(user, contractId, subId);
                    }

                    if (result.ResultStatus == 0)
                        scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.ResultStatus = -1;
            }

            context.Response.Write(serializer.Serialize(result));
            context.Response.End();
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:57,代码来源:ContractInAuditHandler.ashx.cs

示例7: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            NFMT.Common.UserModel user = Utility.UserUtility.CurrentUser;
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            string text = context.Request.Form["text"];
            if (string.IsNullOrEmpty(text))
            {
                result.ResultStatus = -1;
                result.Message = "参数错误";
                context.Response.Write(serializer.Serialize(result));
                context.Response.End();
            }

            List<StockInfo> stockInfos = new List<StockInfo>();

            try
            {
                foreach (string str in text.Split('\n'))
                {
                    if (string.IsNullOrEmpty(str) || str.Split('\t').Length < 5) continue;

                    stockInfos.Add(new StockInfo()
                    {
                        ContractNo = str.Split('\t')[0],
                        NetAmount = Convert.ToDecimal(str.Split('\t')[1]),
                        RefNo = str.Split('\t')[2],
                        Deadline = str.Split('\t')[3],
                        Memo = str.Split('\t')[4]
                    });
                }
                if (stockInfos.Any())
                {
                    result.ResultStatus = 0;
                    result.Message = "处理成功";
                    result.ReturnValue = serializer.Serialize(stockInfos);
                }
                else
                {
                    result.ResultStatus = -1;
                    result.Message = "处理失败";
                }
            }
            catch (Exception e)
            {
                result.ResultStatus = -1;
                result.Message = e.Message;
            }

            context.Response.Write(serializer.Serialize(result));
            context.Response.End();
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:55,代码来源:HandleStockInfo.ashx.cs

示例8: RetailAndPowerTrend

 public ActionResult RetailAndPowerTrend(IDictionary<string, GraphModel> graphModels)
 {
     var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     var months = graphModels.Select(x => x.Key.Substring(0, 3));
     ViewBag.months = serializer.Serialize(months);
     var actualManpowers = graphModels.Select(x => x.Value.ActualManPower);
     ViewBag.actualManPowers = serializer.Serialize(actualManpowers);
     var retails = graphModels.Select(x => x.Value.Retail);
     ViewBag.retails = serializer.Serialize(retails);
     var planManpower = graphModels.Select(x => x.Value.PlanManPower);
     ViewBag.planManPower = serializer.Serialize(planManpower);
     return PartialView();
 }
开发者ID:akhilrex,项目名称:DMP_New,代码行数:13,代码来源:ReportingController.cs

示例9: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/plain";
            //就是将所有的User中的信息添加到主表中 Id, LoginName, Password, Phone, Email, UserState

            List<shaoqi.Model.Announce> list = annBll.GetModelList(" ");
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].AnnContent.Length > 200)
                {
                    list[i].AnnContent = list[i].AnnContent.Substring(0, 200);
                }

                list[i].adminName = adminBll.GetModel(Convert.ToInt32(list[i].AdminId)).LoginName;
            }
            System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();

            //还要查出有多少条记录
            string sqlc = "select count(*) from Announce";
            int count = annBll.GetinfoCount(sqlc);

            var info = new { total = count, rows = list };

            string allinfo = json.Serialize(info);

            context.Response.Write(allinfo);
        }
开发者ID:shaoqiming,项目名称:GitHupProject,代码行数:28,代码来源:GetAllAnnounce.ashx.cs

示例10: ConvertDataTabletoString

 public string ConvertDataTabletoString(string bib)
 {
     DataTable dt = new DataTable();
     using (SqlConnection con = new SqlConnection("Data Source=184.168.194.70;Initial Catalog=ittitudeworks;User ID=rakesh123; [email protected]; Trusted_Connection=False"))
     {
         using (SqlCommand cmd = new SqlCommand("select * from all_triathlon_timing where BIBNumber='" + bib.ToString() + "'", con))
         {
             con.Open();
             SqlDataAdapter da = new SqlDataAdapter(cmd);
             da.Fill(dt);
             System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
             List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
             Dictionary<string, object> row;
             foreach (DataRow dr in dt.Rows)
             {
                 row = new Dictionary<string, object>();
                 foreach (DataColumn col in dt.Columns)
                 {
                     row.Add(col.ColumnName, dr[col]);
                 }
                 rows.Add(row);
             }
             return serializer.Serialize(rows);
         }
     }
 }
开发者ID:rakeshctc,项目名称:ctcpg,代码行数:26,代码来源:data.aspx.cs

示例11: UploadFileAjax

        public void UploadFileAjax()
        {
            HttpRequest request = this.Context.Request;

            HttpPostedFile file = request.Files["file"];
            //Save the file appropriately.
            //file.SaveAs(...);

            string msg = "File Name: " + file.FileName;
            msg += "<br />First Name: " + request["first-name"];
            msg += "<br />Country: " + request["country_Value"];

            var o = new { success = true, msg = msg };
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            HttpContext context = this.Context;
            HttpResponse response = context.Response;

            context.Response.ContentType = "text/html";

            string s = serializer.Serialize(o);
            byte[] b = response.ContentEncoding.GetBytes(s);
            response.AddHeader("Content-Length", b.Length.ToString());
            response.BinaryWrite(b);

            try
            {
                this.Context.Response.Flush();
                this.Context.Response.Close();
            }
            catch (Exception) { }
        }
开发者ID:mex868,项目名称:Nissi.Solution,代码行数:32,代码来源:WebService.cs

示例12: GetQueryTraceAsJson

        public string GetQueryTraceAsJson()
        {
            var trace = GetQueryTrace();

            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            return serializer.Serialize(trace);
        }
开发者ID:NetworkTen,项目名称:SitecoreSearchContrib,代码行数:7,代码来源:QueryTraceScopeSessionProvider.cs

示例13: getSLDuAn_DaDauTu

        public static string getSLDuAn_DaDauTu( List<EntityDuAn> duan)
        {
            string[] mang = new string[] { "#FF99CC", "#CC99CC", "#9999CC", "#6699CC", "#0099CC", "#FF66CC", "#CC99CC", "#6699CC", "#0099CC", "#3366CC", "#00EE00", "#008800", "#002200", "#000044", "#DDC488", "#ECAB53", "#008080", "#FFCC99", "#FFD700", "#9932CC", "#8A2BE2", "#C71585", "#800080", "#FFBF00", "#9966CC", "#7FFFD4", "#007FFF", "#3D2B1F", "	#0000FF", "#DE3163", "#7FFF00", "#50C878", "#DF73FF", "#4B0082", "#FFFF00", "#008080", "#660099", "#FFE5B4" };
            dbFirstStepDataContext db = new dbFirstStepDataContext();
            List<BanDoModel> list = new List<BanDoModel>  ();
            var danhmuc  =  db.EntityDanhMucs.Where(g => g.IdRoot ==1).ToList();
            Random rd = new Random();
            int vt = rd.Next(mang.Count()-danhmuc.Count());
            int i = -1;
            foreach(var item in danhmuc)
            {
                i++;
                BanDoModel bando = new BanDoModel ();
                int sl = duan == null ? 0 : duan.Where(g => g.IdDanhMuc == item.Id).ToList().Count();
                bando.value = 1;
                if (sl > 0)
                {
                    bando.color = mang[vt+i];

                }
                else bando.color = "#f5f5f5";

             //   bando.color = sl > 0 ? "#14c3be" : "#f5f5f5";
                bando.highlight = "#FF5A5E";
                bando.label = item.TenDM.ToString()+"("+sl+")";
                list.Add(bando);
            }

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(list);
            return sJSON;
        }
开发者ID:centaurustech,项目名称:khainguyen-FirstStep,代码行数:32,代码来源:BanDoModel.cs

示例14: ProcessRequest

		public void ProcessRequest(HttpContext context)
		{
			context.Response.ContentType = "application/json";

			//get provided page size
			double width = double.Parse(context.Request.QueryString["Width"]);
			double height = double.Parse(context.Request.QueryString["Height"]);

			var json = new System.Web.Script.Serialization.JavaScriptSerializer();

			//refresh when this is the first load (session width is null) or when size has changed, so we can rearrange layout if we want to
			var refresh = Platform.Current.Page.Width != width || Platform.Current.Page.Height != height;
			var output = json.Serialize(new { Refresh = refresh });

			//save new page size in session
			Session.Current[typeof(Page) + ".Width"] = width;
			Session.Current[typeof(Page) + ".Height"] = height;

			if (refresh && Platform.Current.Controller != null)
			{
				Platform.Current.Controller.Resize();
			}

			context.Response.Write(output);
		}
开发者ID:okhosting,项目名称:OKHOSTING.UI,代码行数:25,代码来源:PageSize.ashx.cs

示例15: getAllUsersJson

 public string getAllUsersJson()
 {
     System.Web.Script.Serialization.JavaScriptSerializer jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
     jsSerializer.MaxJsonLength = 5000000;
     String json = jsSerializer.Serialize(listUsuario());
     return json;
 }
开发者ID:rpoveda,项目名称:WCF_SOAP,代码行数:7,代码来源:UsuarioController.cs


注:本文中的System.Web.Script.Serialization.JavaScriptSerializer.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。