本文介绍了.Net核心中Json()的小写属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有类ClientViewModel:
Have class ClientViewModel:
public class Result
{
public long PKID
{
get;
set;
}
public string Name
{
get;
set;
}
}
并具有post方法来返回此模型:
And have post method to return this model:
[HttpPost]
public JsonResult Search(string orderBy, List<Order> order, Search search,
int start, int length, string searchTerm, bool isAsc, bool hideVoidedAndDeclined, bool recent = false)
{
var take = length;
var skip = start;
var m = _clientsService.Search(searchTerm, orderBy, hideVoidedAndDeclined, isAsc, take, skip, recent);
return Json(m);
}
但是当尝试在json中返回对象时,它看起来是:
but when try to return object in json it looks as:
name:"Nick22"
pkid: 5
但是我需要保存寄存器
Name:"Nick22"
PKID: 5
推荐答案
您应该更改合同解析器.但是,由于您的大小写并不总是相同,因此使用
You should change the contractresolver. But since your casing is not always the same, you might be better off using
services.AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });
services.AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });
这篇关于.Net核心中Json()的小写属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!