json.net

Serializing an integer as hexadecimal in JSON.NET

给你一囗甜甜゛ 提交于 2020-08-26 02:55:55
问题 JSON.NET supports deserializing hexadecimal numbers (e.g. 0xffff ), but how about serializing ? The following works, but seems far too complicated: public sealed class HexJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return typeof(uint).Equals(objectType); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteRawValue($"0x{value:x}"); } public override object ReadJson(JsonReader reader, Type objectType,

Serializing an integer as hexadecimal in JSON.NET

不羁岁月 提交于 2020-08-26 02:55:50
问题 JSON.NET supports deserializing hexadecimal numbers (e.g. 0xffff ), but how about serializing ? The following works, but seems far too complicated: public sealed class HexJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return typeof(uint).Equals(objectType); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteRawValue($"0x{value:x}"); } public override object ReadJson(JsonReader reader, Type objectType,

Serializing an integer as hexadecimal in JSON.NET

邮差的信 提交于 2020-08-26 02:55:43
问题 JSON.NET supports deserializing hexadecimal numbers (e.g. 0xffff ), but how about serializing ? The following works, but seems far too complicated: public sealed class HexJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return typeof(uint).Equals(objectType); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteRawValue($"0x{value:x}"); } public override object ReadJson(JsonReader reader, Type objectType,

Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'System.Collections.Generic.List`

心不动则不痛 提交于 2020-08-22 05:29:13
问题 l am reading data from webservice. The json object looks like: var goldString = [ { "date":"20151109", "day":30, "month":"November", "year":2015, "club":9, "clubName":"Flamingo", "itw":"XYD", "races":{ "1":{ "race":1, "time":"12:20", "raceStatus":"Undecided", "reference":91, "name":"WELCOME TO FLAMINGO PARK MAIDEN PLATE", "description":"For Maidens", "distance":1000, "stake":"R46,000", "stakes":"1st: R28,750 | 2nd: R9,200 | 3rd: R4,600 | 4th: R2,300 | 5th: R1,150", "surface":"Sand", "going":"

Migration to .NET Core 3.1 - Netwonsoft missing

空扰寡人 提交于 2020-08-20 11:12:19
问题 I just migrated to ASP.NET Core 3.1 from 2.2 and I am getting this error: System.NotSupportedException: The collection type 'System.Collections.Generic.Dictionary`2[System.Object,System.Object]' is not supported. at System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options) at System.Text.Json.JsonClassInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, Type implementedPropertyType, PropertyInfo

Querying JSON using SelectTokens? With Newtonsoft.Json.Linq in C#

烂漫一生 提交于 2020-08-19 10:43:35
问题 I'm trying to make use of Netwonsoft.JSON.Linq in C#, to change the "statusCode" values in the following JSON: { "disbursements":[ { "id":"1f337641", "contactId":"f5eb2", "statusCode":166000005, "amount":8, "category":166000001 }, { "id":"027a4762", "contactId":"f5eb2038", "statusCode":166000000, "amount":4000, "category":166000000 } ] } So, inside the JSON data is: "disbursements" which is JSON array. I have to change the "statusCode" of each item in the array to 166000005 . I'm able to

Querying JSON using SelectTokens? With Newtonsoft.Json.Linq in C#

a 夏天 提交于 2020-08-19 10:41:05
问题 I'm trying to make use of Netwonsoft.JSON.Linq in C#, to change the "statusCode" values in the following JSON: { "disbursements":[ { "id":"1f337641", "contactId":"f5eb2", "statusCode":166000005, "amount":8, "category":166000001 }, { "id":"027a4762", "contactId":"f5eb2038", "statusCode":166000000, "amount":4000, "category":166000000 } ] } So, inside the JSON data is: "disbursements" which is JSON array. I have to change the "statusCode" of each item in the array to 166000005 . I'm able to

ASP.NET Core 使用 Redis 和 Protobuf 进行 Session 缓存

我们两清 提交于 2020-08-18 04:30:01
原文: ASP.NET Core 使用 Redis 和 Protobuf 进行 Session 缓存 前言 上篇博文 介绍了怎么样在 asp.net core 中使用中间件,以及如何自定义中间件。项目中刚好也用到了Redis,所以本篇就介绍下怎么样在 asp.net core 中使用 Redis 进行资源缓存和Session缓存。 如果你觉得对你有帮助的话,不妨点个【推荐】。 目录 Redis 介绍 asp.net core Session 介绍 Redis & Session 实例讲解 Session的使用 使用 Protobuf 给 Session添加扩展方法 Redis 介绍 下面是 Redis官网 的介绍: Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis