JSON.NET serializes an object where the name of the property that begins with a period

Is it possible to do the following:

I have a class:

public class Customer
{
    public Csutomer()
    {
    }

    public string Name { get; set; }
}

and then I instantiate the class:

Customer cust = new Customer();
cust.Name = "Jhon Smith";

string result = JsonConvert.SerializeObject(cust);

and the result will contain:

{"Name":"Jhon Smith"}

I need to get json like this, pay attention to the dot .in front of the name.Name

{".Name":"Jhon Smith"}

And after that, to parse Json on my object.

+4
source share
1 answer

Declare your property as:

[JsonProperty(".Name")]
public string Name { get; set; }
+12
source

All Articles