I need to make a JSON string like this using JSON.NET:
{
"description": "the description",
"public": true,
"files": {
"index.html": {
"content": "some value"
}
}
}
So how can I do that?
I tried creating a class for it, but I don't know how to create a field with name "public" because public is C# keyword.
1 个答案:
答案 0 :(得分:2)
The property name could be anything you want, but if you want the value to map to it, you need to add the JsonProperty attribute indicating the name of the property.
public class MyObject
{
public string Description { get; set; }
[JsonProperty("public")]
public bool IsPublic { get; set; }
public Dictionary<string, JObject> Files { get; set; }
}