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


C# System.ToJson方法代码示例

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


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

示例1: SynchItemAsync

		public async Task SynchItemAsync( InventoryItemSubmit item, bool isCreateNew = false, Mark mark = null )
		{
			if( mark.IsBlank() )
				mark = Mark.CreateNew();

			var parameters = new { item, isCreateNew };

			try
			{
				ChannelAdvisorLogger.LogStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : parameters.ToJson() ) );

				await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo( this.AdditionalLogInfo ) ).Do( async () =>
				{
					ChannelAdvisorLogger.LogTraceRetryStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : parameters.ToJson() ) );
					if( !isCreateNew && !( await this.DoesSkuExistAsync( item.Sku, mark ) ) )
						return;

					var resultOfBoolean = await this._client.SynchInventoryItemAsync( this._credentials, this.AccountId, item ).ConfigureAwait( false );
					CheckCaSuccess( resultOfBoolean.SynchInventoryItemResult );
					ChannelAdvisorLogger.LogTraceRetryEnd( this.CreateMethodCallInfo( mark : mark, methodResult : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : resultOfBoolean.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : parameters.ToJson() ) );
				} ).ConfigureAwait( false );
				ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : "void", additionalInfo : this.AdditionalLogInfo(), methodParameters : parameters.ToJson() ) );
			}
			catch( Exception exception )
			{
				var channelAdvisorException = new ChannelAdvisorException( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo() ), exception );
				ChannelAdvisorLogger.LogTraceException( channelAdvisorException );
				throw channelAdvisorException;
			}
		}
开发者ID:agileharbor,项目名称:channelAdvisorAccess,代码行数:30,代码来源:ItemsServiceUpdateItems.cs

示例2: ShouldHandlerConvertCardFromCheckList

        public void ShouldHandlerConvertCardFromCheckList()
        {
            // Setup
            var time1 = DateTime.Parse("2012-01-01");
            var list1 = new List {Id = "list-1-id"};
            var card = new Card {Id = "card-id", List = list1};
            var lists = List.CreateLookupFunction(list1);
            var convertCardAction = new
                {
                    type = Action.ConvertToCardFromCheckItem,
                    date = time1.ToString("o")
                };

            var actions = new
                {
                    actions = new[]
                        {
                            convertCardAction
                        }
                };

            // Exercise
            _parser.ProcessCardHistory(card, actions.ToJson(), lists);

            // Verify
            var actualListHistory = GetActualHistory(card);
            var expectedListHistory = new[]
                {
                    new {List = list1, StartTime = (DateTime?)time1, EndTime = (DateTime?) null},
                };
            Assert.That(actualListHistory, Is.EqualTo(expectedListHistory));
        }
开发者ID:falck-it-dev,项目名称:trello-spc,代码行数:32,代码来源:ParseCardsTest.cs

示例3: RecieveFile

        /// <summary>
        /// 文件上传
        /// </summary>
        private void RecieveFile() {
    
            HttpFileCollection files = Request.Files;
            if (files.Count > 0) {
               
                int errCount = 0;

                if (files.Count == 1) {
                    //异步批量上传
                    var file = files[0];
                    errCount += Upload(file);

                    if (errCount == 0) {
                        //成功
                        var obj = new {success = "1"};
                        Response.Write(obj.ToJson());
                    }
                }
                else if (files.Count > 1) {
                    //同步批量上传

                    for (int i = 0; i < files.Count; i++) {
                        var file = files[i];
                        errCount += Upload(file);
                    }

                    if (errCount == 0) {
                        //成功
                        var obj = new {success = "1"};
                        Response.Write(obj.ToJson());
                    }

                }
            }
        }
开发者ID:TheTypoMaster,项目名称:DotNet.Mix,代码行数:38,代码来源:Uprecieve.aspx.cs

示例4: ShouldNotComplainAboutUnknownCardOrListId

 public void ShouldNotComplainAboutUnknownCardOrListId()
 {
     var data = new { actions = new [] { new { data = new { card = new { id = "bad-card-id" } } } } ,
                      cards = new object[0] };
     var json = data.ToJson();
     Assert.That(() => _parser.GetCards(json), Throws.Nothing);
 }
开发者ID:falck-it-dev,项目名称:trello-spc,代码行数:7,代码来源:ParseCardsTest.cs

示例5: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            try
            {
                var version = Engine.Persister.Get(int.Parse(context.Request[PathData.ItemQueryKey]));
                if (!version.VersionOf.HasValue)
                {
                    context.Response.Write(new { success = false, message = "Item #" + version.ID + " is not a version." }.ToJson());
                    return;
                }
                if (!version.IsPage)
                {
                    context.Response.Write(new { success = true, master = new { id = version.VersionOf.ID }, message = "Part version removed" }.ToJson());
					Engine.Persister.Delete(version);
                    return;
                }

                var newVersion = Engine.Resolve<UpgradeVersionWorker>().UpgradeVersion(version);
                var result = new { success = true, master = new { id = newVersion.Master.ID }, version = new { id = newVersion.ID, index = newVersion.VersionIndex } };
                context.Response.Write(result.ToJson());
            }
            catch (Exception ex)
            {
                new Logger<UpgradeVersionHandler>().Error("Error migrating #" + context.Request[PathData.ItemQueryKey], ex);
                context.Response.Write(new { success = false, message = ex.Message, stacktrace = ex.ToString() }.ToJson());
            }
        }
开发者ID:EzyWebwerkstaden,项目名称:n2cms,代码行数:28,代码来源:UpgradeVersion.ashx.cs

示例6: TestSerializeAnonymousClass

 public void TestSerializeAnonymousClass()
 {
     object a = new { X = 1 };
     var json = a.ToJson();
     var expected = "{ 'X' : 1 }".Replace("'", "\"");
     Assert.AreEqual(expected, json);
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp140Tests.cs

示例7: JsonPCallback

    public void JsonPCallback()
    {
        string Callback = Request.QueryString["jsonp"];
        if (!string.IsNullOrEmpty(Callback))
        {
            var sessionsQuery = new SessionsQuery();
            if (HttpContext.Current.Request["query"] != null)
            {
                sessionsQuery = HttpContext.Current.Request["query"].FromJson<SessionsQuery>();
            }
            sessionsQuery.CodeCampYearId = Utils.CurrentCodeCampYear;

            sessionsQuery.WithTags = true;

            if (HttpContext.Current.Request["start"] != null && HttpContext.Current.Request["limit"] != null)
            {
                sessionsQuery.Start = Convert.ToInt32(HttpContext.Current.Request["start"]);
                sessionsQuery.Limit = Convert.ToInt32(HttpContext.Current.Request["limit"]);
            }

            var listData1 = new List<SessionsResult>();
            var sessionsManager = new SessionsManager();
            //if (HttpContext.Current.User.Identity.IsAuthenticated
            // && Utils.CheckUserIsAdmin())
            {
                listData1 = sessionsManager.Get(sessionsQuery);
                for (int i = 0; i < listData1.Count; i++)
                {
                    listData1[i].AdminComments = null;
                    listData1[i].InterestCount = "";
                    listData1[i].InterestedCount = 0;
                    listData1[i].NotInterestedCount = 0;
                    listData1[i].PlanAheadCount = "";
                    listData1[i].PlanAheadCountInt = 0;
                    listData1[i].SessionEvalsResults = null;
                    listData1[i].SpeakerPictureUrl = "http://www.siliconvalley-codecamp.com/" + listData1[i].SpeakerPictureUrl;
                    listData1[i].TitleWithPlanAttend = "";
                    listData1[i].Username = "";
                    listData1[i].WillAttendCount = 0;
                    listData1[i].WikiURL = "";
                    listData1[i].SpeakersList = null;

                }
            }

            var listData2 = (from data in listData1 orderby data.SessionTime, data.Title.ToUpper() select data).ToList();

            var ret = new { success = true, rows = listData2, total = sessionsQuery.OutputTotal };
            //HttpContext.Current.Response.ContentType = "text/plain";
            //HttpContext.Current.Response.Write(ret.ToJson());

            // *** Do whatever you need
            //Response.Write(Callback + "( {\"x\":10 , \"y\":100} );");

            Response.Write(Callback + "( " + ret.ToJson() + " );");
        }

        Response.End();
    }
开发者ID:suwatch,项目名称:svcodecampweb,代码行数:59,代码来源:SessionsJSONP.aspx.cs

示例8: BuildErrorJson

 public static string BuildErrorJson(string type_name, string err_msg, NameValueCollection col)
 {
     var item = new
     {
         api_name = type_name,
         err_msg = err_msg,
         query = col.ToDictionary().ToJson(),
     };
     return item.ToJson();
 }
开发者ID:ChobitsSP,项目名称:Top.Rest,代码行数:10,代码来源:RequestUtils.cs

示例9: BuildRequest

 public override HttpRequestItem BuildRequest()
 {
     var req = HttpRequestItem.CreateJsonRequest(ApiUrls.TulingRobot);
     var obj = new
     {
         key = _key,
         info = _input,
         userid = Session.User.UserName,
     };
     req.RawData = obj.ToJson();
     return req;
 }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:12,代码来源:GetTuringRobotReplyAction.cs

示例10: TestAnonymousClass

        public void TestAnonymousClass() {
            var obj = new {
                I = 1,
                D = 1.1,
                S = "Hello"
            };
            var json = obj.ToJson();
            var expected = "{ 'I' : 1, 'D' : 1.1, 'S' : 'Hello' }".Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            Assert.Throws<InvalidOperationException>(() => BsonSerializer.Deserialize(bson, obj.GetType()));
        }
开发者ID:kamiff,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonDefaultSerializerTests.cs

示例11: BuildRequest

 public override HttpRequestItem BuildRequest()
 {
     var url = string.Format(ApiUrls.SendMsg, Session.BaseUrl);
     var obj = new
     {
         Session.BaseRequest,
         Msg = _msg
     };
     var req = new HttpRequestItem(HttpMethodType.Post, url)
     {
         RawData = obj.ToJson(),
         ContentType = HttpConstants.JsonContentType
     };
     return req;
 }
开发者ID:huoshan12345,项目名称:iQQ.Net,代码行数:15,代码来源:SendMsgAction.cs

示例12: TestTableMegaListJson

 public ActionResult TestTableMegaListJson(JqGridParam jqgridparam)
 {
     Stopwatch watch = CommonHelper.TimerStart();
     string UserId = ManageProvider.Provider.Current().UserId;
     DataTable ListData = this.FindTablePageBySql("SELECT TestId, Code, FullName, CreateDate, CreateUserName, Remark FROM TestTable", ref jqgridparam);
     var JsonData = new
     {
         total = jqgridparam.total,
         page = jqgridparam.page,
         records = jqgridparam.records,
         costtime = CommonHelper.TimerEnd(watch),
         rows = ListData,
     };
     return Content(JsonData.ToJson());
 }
开发者ID:Lotus-wiki,项目名称:zero,代码行数:15,代码来源:HadoopController.cs

示例13: Serialize_An_Array

        public void Serialize_An_Array()
        {
            // arrange
            var expected = @"[{""X"":""test""},{""X"":""test1""},{""X"":""test2""}]";
            var body = new[] {
                new { X = "test" },
                new { X = "test1" },
                new { X = "test2" }
            };

            // act
            var actual = body.ToJson();

            // assert
            Assert.AreEqual(expected, actual);
        }
开发者ID:managedfusion,项目名称:managedfusion,代码行数:16,代码来源:JsonTest.cs

示例14: DbBackupList

 /// <summary>
 ///【备份计划】返回列表JONS
 /// </summary>
 /// <returns></returns>
 public ActionResult DbBackupList()
 {
     try
     {
         List<Base_BackupJob> ListData = DataFactory.Database().FindList<Base_BackupJob>("ORDER BY CreateDate DESC");
         var JsonData = new
         {
             rows = ListData,
         };
         return Content(JsonData.ToJson());
     }
     catch (Exception ex)
     {
         Base_SysLogBll.Instance.WriteLog("", OperationType.Query, "-1", "异常错误:" + ex.Message);
         return null;
     }
 }
开发者ID:Lotus-wiki,项目名称:zero,代码行数:21,代码来源:DataBaseController.cs

示例15: Form1_Load

		private void Form1_Load(object sender, EventArgs e)
		{
			var sampleObject = new 
			{
				ReportDate = DateTime.Now,
				DepartmentList = new []
				{
					new 
					{
						DepartmentName = "Developers",
						EmployeeList = new []
						{
							new { FirstName="Essie", LastName="Vaill" },
							new { FirstName="Cruz", LastName="Roudabush" },
							new { FirstName="Billie", LastName="Tinnes" },
							new { FirstName="Lashawn", LastName="Hasty" },
							new { FirstName="Marianne", LastName="Earman" }
						}
					},
					new 
					{
						DepartmentName = "QA",
						EmployeeList = new []
						{
							new { FirstName="Zackary", LastName="Mockus" },
							new { FirstName="Rosemarie", LastName="Fifield" },
							new { FirstName="Bernard", LastName="Laboy" },
						}
					},
					new
					{
						DepartmentName = "ProjectManagemnt",
						EmployeeList = new []
						{
							new { FirstName="Sue", LastName="Haakinson" },
							new { FirstName="Valerie", LastName="Pou" },
						}
					}
				}
			};
			_txtJson.Text = sampleObject.ToJson(true);
			_txtRazorView.Text = Resources.RazorSampleView;
			this.UpdatePreview();
			this.UpdateSmtpSettings();
		}
开发者ID:mmooney,项目名称:MMDB.RazorEmail,代码行数:45,代码来源:Form1.cs


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