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


C# Json.JsonSerializerSettings类代码示例

本文整理汇总了C#中Newtonsoft.Json.JsonSerializerSettings的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializerSettings类的具体用法?C# JsonSerializerSettings怎么用?C# JsonSerializerSettings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: MetaController

        public MetaController()
        {
            JsonSerializerSettings jSettings = new Newtonsoft.Json.JsonSerializerSettings();
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = jSettings;

            _serializer = new SerializeLibra.JsonSerializer();
        }
开发者ID:soramusoka,项目名称:gbn-ui,代码行数:7,代码来源:MetaController.cs

示例2: JsonFormatter

 static JsonFormatter()
 {
     SerializerSettings = new JsonSerializerSettings
     {
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     };
 }
开发者ID:ZOXEXIVO,项目名称:ServerMonitoring,代码行数:7,代码来源:JsonFormatter.cs

示例3: Reddit

 public Reddit()
 {
     JsonSerializerSettings = new JsonSerializerSettings();
     JsonSerializerSettings.CheckAdditionalContent = false;
     JsonSerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
     _webAgent = new WebAgent();
 }
开发者ID:BigRedPK,项目名称:RedditSharp,代码行数:7,代码来源:Reddit.cs

示例4: RegisterApis

        public static void RegisterApis(HttpConfiguration config)
        {
            var serializerSettings = new JsonSerializerSettings();
            serializerSettings.Converters.Add(new IsoDateTimeConverter());

            config.Formatters[0] = new JsonNetFormatter(serializerSettings);
            config.Formatters.Add(new ProtoBufFormatter()); 
            config.Formatters.Add(new ContactPngFormatter());
            config.Formatters.Add(new VCardFormatter());
            config.Formatters.Add(new ContactCalendarFormatter());
            
            config.MessageHandlers.Add(new UriFormatExtensionHandler(new UriExtensionMappings()));
            
            //var loggingRepo = config.ServiceResolver.GetService(typeof(ILoggingRepository)) as ILoggingRepository;
            //config.MessageHandlers.Add(new LoggingHandler(loggingRepo));

            config.MessageHandlers.Add(new NotAcceptableHandler());

            ConfigureResolver(config);

            config.Routes.MapHttpRoute(
                "Default",
                "{controller}/{id}/{ext}",
                new { id = RouteParameter.Optional, ext = RouteParameter.Optional });
        }
开发者ID:robfinner,项目名称:Thinktecture.Web.Http,代码行数:25,代码来源:Global.asax.cs

示例5: ToString

		public override string ToString()
		{
			JsonSerializerSettings settings = new JsonSerializerSettings();
			settings.Formatting = Formatting.Indented;
			settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
			return JsonConvert.SerializeObject(this, settings);
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:7,代码来源:MicroChannelArguments.cs

示例6: Install

        public static new void Install(HttpConfiguration config, IAppBuilder app)
        {
            config.SuppressHostPrincipal();

            app.UseCors(CorsOptions.AllowAll);

            app.MapSignalR();

            var jSettings = new JsonSerializerSettings();

            jSettings.Formatting = Formatting.Indented;

            jSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Formatters.JsonFormatter.SerializerSettings = jSettings;

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
开发者ID:QuinntyneBrown,项目名称:SavingsNearMe,代码行数:26,代码来源:ApiConfiguration.cs

示例7: MobileServiceSerializerTests

 static MobileServiceSerializerTests()
 {
     var settings = new JsonSerializerSettings();
     settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
     settings.DateFormatString = "yyyy-MM-dd'T'HH:mm:ss.fff'Z'";
     MinDateTimeSerializedToJson = JsonConvert.SerializeObject(default(DateTime).ToUniversalTime(), settings);
 }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:7,代码来源:MobileServiceSerializer.Test.cs

示例8: ToJson

 public static string ToJson( this object val )
 {
     var settings = new JsonSerializerSettings {
         ReferenceLoopHandling = ReferenceLoopHandling.Ignore
     };
     return JsonConvert.SerializeObject( val, Formatting.Indented, settings );
 }
开发者ID:vijaysg,项目名称:NuFetch,代码行数:7,代码来源:NuFetchExtensions.cs

示例9: JsonNetResult

 public JsonNetResult()
 {
     Settings = new JsonSerializerSettings
     {
         ReferenceLoopHandling = ReferenceLoopHandling.Error
     };
 }
开发者ID:GasiorowskiPiotr,项目名称:EvilDuck.Web.Cms,代码行数:7,代码来源:JsonNetResult.cs

示例10: CanSerializeAndDeserializeAScope

        public void CanSerializeAndDeserializeAScope()
        {
            var s1 = new Scope
            {
                Name = "email",
                Required = true,
                Type = ScopeType.Identity,
                Emphasize = true,
                DisplayName = "email foo",
                Description = "desc foo",
                Claims = new List<ScopeClaim> {
                    new ScopeClaim{Name = "email", Description = "email"}
                }
            };
            var s2 = new Scope
            {
                Name = "read",
                Required = true,
                Type = ScopeType.Resource,
                Emphasize = true,
                DisplayName = "foo",
                Description = "desc",
            };
            var converter = new ScopeConverter(new InMemoryScopeStore(new Scope[] { s1, s2 }));

            var settings = new JsonSerializerSettings();
            settings.Converters.Add(converter);
            var json = JsonConvert.SerializeObject(s1, settings);

            var result = JsonConvert.DeserializeObject<Scope>(json, settings);
            Assert.Same(s1, result);
        }
开发者ID:ircnelson,项目名称:TwentyTwenty.IdentityServer4.EntityFramework7,代码行数:32,代码来源:ScopeConverterTests.cs

示例11: LogFailedMessage

 public static void LogFailedMessage(object messageObj)
 {
     if (LogConfig.IsLoggingEnabled)
     {
         try
         {
             //log.SessionId = ApplicationContext.GetSessionId();
             var dataProvider = new LoggingDataProvider();
             var settings = new JsonSerializerSettings()
             {
                 TypeNameHandling = TypeNameHandling.Objects,
             };
             var log = new Log()
             {
                 Name = "FailedMessageItem",
                 ServiceName = messageObj.GetType().Name,
                 Request = JsonConvert.SerializeObject(messageObj, settings),
             };
             if (LogConfig.IsLogAsyncEnabled)
             {
                 Task.Factory.StartNew(() => dataProvider.SaveLog(log));
             }
             else
             {
                 dataProvider.SaveLog(log);
             }
         }
         catch (Exception ex)
         {
             File.AppendAllText("Logs.txt", "LogMessage method failed" + ex.ToString());
         }
     }
 }
开发者ID:TokleMahesh,项目名称:BG,代码行数:33,代码来源:Logger.cs

示例12: OnActionExecuting

        /// <summary>
        /// Called before an action method executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Continue normally if the model is valid.
            if (filterContext == null || filterContext.Controller.ViewData.ModelState.IsValid)
            {
                return;
            }

            var serializationSettings = new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };

            // Serialize Model State for passing back to AJAX call
            var serializedModelState = JsonConvert.SerializeObject(
              filterContext.Controller.ViewData.ModelState,
              serializationSettings);

            var result = new ContentResult
            {
                Content = serializedModelState,
                ContentType = "application/json"
            };

            filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            filterContext.Result = result;
        }
开发者ID:targitaj,项目名称:m3utonetpaleyerxml,代码行数:31,代码来源:FormValidatorAttribute.cs

示例13: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
                string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
                throw new InvalidOperationException("This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.");

            var response = context.HttpContext.Response;

            response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";

            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;

            if (Data == null) return;

            var jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            response.Write(JsonConvert.SerializeObject(Data, Formatting.Indented, jsonSerializerSettings));
        }
开发者ID:richardrcruzc,项目名称:skimur,代码行数:25,代码来源:JsonNetResult.cs

示例14: JsonNetFormatter

        public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings) {

            _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings();

            SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
            Encoding = new UTF8Encoding(false, true);
        }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:7,代码来源:JsonNetFormatter.cs

示例15: Login

		public async Task<LoginResult> Login(string username, string password) {
			var json = "";

			if (string.IsNullOrEmpty (username) || string.IsNullOrEmpty (password)) {
				return new LoginResult {
					Successful = false
				};
			}

			using (var client = new HttpClient ()) {
				using (var message = new HttpRequestMessage (HttpMethod.Post, BaseUrl + "/account/login")) {

					var userPass = string.Format("{0}:{1}", username, password);
					var encoded = Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(userPass));
					message.Headers.Add("Authorization", String.Format("Basic {0}", encoded));

					var result = await client.SendAsync(message);
					json = await result.Content.ReadAsStringAsync();
				}
			}

			var settings = new JsonSerializerSettings
			{
				MissingMemberHandling = MissingMemberHandling.Ignore,
				NullValueHandling = NullValueHandling.Ignore
			};
			var loginCredentials = JsonConvert.DeserializeObject<LoginResult>(json, settings);
			return loginCredentials;

		}
开发者ID:ryanerdmann,项目名称:angora,代码行数:30,代码来源:KiwiLoginService.cs


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