【发布时间】:2021-10-22 04:37:28
【问题描述】:
我有一个带有下划线的小写字段
public class Project
{
public int project_id { get; set; }
public long account_id { get; set; }
public long user_id { get; set; }
public string name { get; set; }
public string description { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
}
当 GET、POST 等 API 命中 API 时,我需要以驼峰形式进行序列化。 我该怎么做?
json 是这样的:
{
"project_id": 10,
"account_id": 10,
"user_id": 10,
"name": "string",
"description": "string",
"created_at": "Date",
"updated_at": "Date"
}
我想要这种格式:
{
"projectId": 10,
"accountId": 10,
"userId": 10,
"name": "string",
"description": "string",
"createdAt": "Date",
"updatedAt": "Date"
}
【问题讨论】:
-
另外,这意味着您可以根据 C# 约定命名您的属性
-
如果你使用的是系统文本Json,过程是一样的,但是属性叫做JsonPropertyName。如果您使用的是 JavaScriptSerializer,请升级
标签: c# .net asp.net-core