當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。