相关疑难解决方法(0)

使用System.Text.Json的JsonConverter等效项

我开始将.net Core 3.0应用程序中的一些代码从迁移Newtonsoft.JsonSystem.Text.Json

我从迁移了属性

[JsonProperty("id")][JsonPropertyName("id")]

但是我有一些属性装饰有如下JsonConverter属性:

[JsonConverter(typeof(DateTimeConverter))] [JsonPropertyName("birth_date")] DateTime BirthDate{ get; set; }

但是我在System.Text.Json“ 牛顿软件”转换器中找不到与之等效的东西。有人知道如何在.net Core 3.0中实现吗?

谢谢!

c# json .net-core .net-core-3.0 system.text.json

11
推荐指数
1
解决办法
3230
查看次数

JSON值无法转换为System.Int32

我想将对象数据发送到我的Web API。api接受一个class参数,其属性是int和string的类型。

这是我的课:

public class deneme
    {
        public int ID { get; set; }
        public int sayi { get; set; }
        public int reqem { get; set; }
        public string yazi { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的json对象:

{
"id":0,
"sayi":"9",
"reqem":8,
"yazi":"sss"
Run Code Online (Sandbox Code Playgroud)

}

我希望api将属性“ sayi”读取为整数。但是由于无法显示,因此出现错误:无法将JSON值转换为System.Int32。路径:$。sayi

我该如何解决这个问题?

asp.net-core-webapi

1
推荐指数
4
解决办法
2189
查看次数