本文整理汇总了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();
}
示例2: JsonFormatter
static JsonFormatter()
{
SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
}
示例3: Reddit
public Reddit()
{
JsonSerializerSettings = new JsonSerializerSettings();
JsonSerializerSettings.CheckAdditionalContent = false;
JsonSerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
_webAgent = new WebAgent();
}
示例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 });
}
示例5: ToString
public override string ToString()
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
return JsonConvert.SerializeObject(this, settings);
}
示例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 }
);
}
示例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);
}
示例8: ToJson
public static string ToJson( this object val )
{
var settings = new JsonSerializerSettings {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
return JsonConvert.SerializeObject( val, Formatting.Indented, settings );
}
示例9: JsonNetResult
public JsonNetResult()
{
Settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Error
};
}
示例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());
}
}
}
示例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;
}
示例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));
}
示例14: JsonNetFormatter
public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings) {
_jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings();
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
Encoding = new UTF8Encoding(false, true);
}
示例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;
}