json.net

System.Security.Permissions missing when invoking JsonConvert.DeserializeObject<T> in .NET Core 2.0

谁都会走 提交于 2020-05-07 12:49:08
问题 I am currently looking at using .NET Core 2.0 so that I can run my app on multiple platforms. One thing I need to do is take an incoming string and deseralise it into an object. e.g. var resultingObject = JsonConvert.DeserializeObject<MyDataContract>(request); In full .NET, this would run and return me my object. However in .NET Core 2.0 I get the following exception Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

.Net 的动态对象(一)概念

纵饮孤独 提交于 2020-05-06 06:49:46
前言 在js里面我们想要给一个对象的属性赋值,或者调用一个对象里面的方法,一般是: var o = {}; o.name = 'yyy'; o.ShowName=function(name){//TODO} 如果是在 .net中,不使用动态对象的话,就只有先定义好我们的属性和方法,再直接去调用,有了动态对象后,我们也可以做类似的事情 dynamic model = new ExpandoObject(); model.name = "xx"; model.ShowName = new Func<string, string>((name) => { return "the name property is " + name; }); model.ShowOwenName = new Func<dynamic, string>((sender) => { return "the name property is " + sender.name; }); Console.WriteLine(model.name); Console.WriteLine(model.ShowName("x")); Console.WriteLine(model.ShowOwenName(model)); 概述 dynamic是FrameWork4.0的新特性。dynamic的出现让C

JsonConvert.PopulateObject() is not handling the decimal type data properly

你。 提交于 2020-04-30 08:11:43
问题 I have a JSON string: {"PaymentVoucherNumber":15,"PaymentVoucherDate":"2019-09-10T00:00:00","pvExpiryDate":"2019-09-22T00:00:00","Amount":35.000,"ReceiptNumber":0} In this json the Amount is a double value. public partial class VoucherList { [JsonProperty("PaymentVoucherNumber")] public long PaymentVoucherNumber { get; set; } [JsonProperty("PaymentVoucherDate")] public string PaymentVoucherDate { get; set; } [JsonProperty("pvExpiryDate")] public string PvExpiryDate { get; set; } [JsonProperty

JsonConvert.PopulateObject() is not handling the decimal type data properly

谁说我不能喝 提交于 2020-04-30 08:10:47
问题 I have a JSON string: {"PaymentVoucherNumber":15,"PaymentVoucherDate":"2019-09-10T00:00:00","pvExpiryDate":"2019-09-22T00:00:00","Amount":35.000,"ReceiptNumber":0} In this json the Amount is a double value. public partial class VoucherList { [JsonProperty("PaymentVoucherNumber")] public long PaymentVoucherNumber { get; set; } [JsonProperty("PaymentVoucherDate")] public string PaymentVoucherDate { get; set; } [JsonProperty("pvExpiryDate")] public string PvExpiryDate { get; set; } [JsonProperty

C# NewtonSoft DeserializeObject error

蓝咒 提交于 2020-04-30 06:54:27
问题 The strange thing is that it works fine on my local deploy (Win 10 IIS) but when I deploy it to our UAT server, it goes nuts. I'm trying to deserialize the following json string: { "header": { "application-code": "ZZZ" }, "piece": [ "0000001" ] } The classes that represent this are defined: public class RequestPiece { [JsonProperty(PropertyName = "header")] public RequestHeaderPiece requestheader { get; set; } } public class ResponseHeaderPiece { [JsonProperty(PropertyName = "application-code

【Json】1.Newtonsoft—Json.NET常用方法简述

萝らか妹 提交于 2020-04-22 03:50:04
Json.NET常用方法汇总(可解决日常百分之90的需求) 0.Json.NET基础用法   首先去 官网 下载最新的Newtonsoft.Json.dll(也可以使用VS自带的NuGet搜索Json.NET下载(下载下图第二个))并引用至项目。    (1)序列化实体类(将实体类对象序列化为Json字符串) using System; using Newtonsoft.Json; namespace Json_NET_Test { /// <summary> /// 定义一个实体类 /// </summary> public class Student { public string Name; public int Age; public string Class; } class Program { static void Main( string [] args) { // 创建实体类对象 Student stu = new Student { Name = " 老王 " , Age = 99 , Class = " 三班 " }; // 开始序列化 string jsonStr = JsonConvert.SerializeObject(stu, Formatting.Indented); Console.WriteLine(jsonStr); } } }   结果:  

JsonPatchDocument is null after migration to .Net Core 3

让人想犯罪 __ 提交于 2020-04-18 06:48:27
问题 I have a AspNetCore-WebApi-Project with several patch-operations, which worked fine with Core 2.2. After migration to Core 3 the [FromBody] JsonPatchDocument<T> is null. My Get/Post-Methods are still functioning as expected. This is one part of my Startup: services.AddDbContext<MyContext>(options => options .UseLazyLoadingProxies() .UseNpgsql(Configuration.GetConnectionString("MyConnectionString"), opt => opt.UseNodaTime())); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {

Call default JsonSerializer in a JsonConverter for certain value type arrays

a 夏天 提交于 2020-04-16 12:58:33
问题 I'm trying to achieve roughly what's described here: Recursively call JsonSerializer in a JsonConverter In short; To examine a value being deserialised, then either consume it in my own code, or hand it off the the default deserializer. The example uses a nifty trick to avoid the same custom code being called recursively: ... else if (reader.TokenType == JsonToken.StartObject) // Use DummyDictionary to fool JsonSerializer into not using this converter recursively dictionary = serializer

Call default JsonSerializer in a JsonConverter for certain value type arrays

点点圈 提交于 2020-04-16 12:57:14
问题 I'm trying to achieve roughly what's described here: Recursively call JsonSerializer in a JsonConverter In short; To examine a value being deserialised, then either consume it in my own code, or hand it off the the default deserializer. The example uses a nifty trick to avoid the same custom code being called recursively: ... else if (reader.TokenType == JsonToken.StartObject) // Use DummyDictionary to fool JsonSerializer into not using this converter recursively dictionary = serializer

How to add a root node to a JSON in C# using Json.NET?

大兔子大兔子 提交于 2020-04-14 06:04:14
问题 I am working on Visual Studio C# project and I need to convert a JSON to XML . I receive the JSON in string format. The problem is, I need to have a root node in the JSON structure if the JSON doesn't have one, so that I can convert to XML with desired format. Supose I have this JSON : { "id": 1, "name": { "first": "Yong", "last": "Mook Kim" }, "contact": [{ "type": "phone/home", "ref": "111-111-1234" }, { "type": "phone/work", "ref": "222-222-2222" }] } And I want to add root node to that