是否有可能达到以下目的:
我有一个类:
public class Customer
{
public Csutomer()
{
}
public string Name { get; set; }
}
然后我实例化我的类:
Customer cust = new Customer();
cust.Name = "Jhon Smith";
string result = JsonConvert.SerializeObject(cust);
结果将包含:
{"Name":"Jhon Smith"}
我需要的是像这样获取 json,注意 Name .Name
之前的点 .
{".Name":"Jhon Smith"}
然后将 Json 解析回我的对象。
最佳答案
将您的属性(property)声明为:
[JsonProperty(".Name")]
public string Name { get; set; }
关于c# - JSON.NET 序列化对象,其中属性名称以点开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25251560/