案例: 我从第三方服务器收到一个 JSON 字符串,其中包含一个对象列表。 例如 [{"foo": "bar", "someotherfield": "somevalue"}, {etc}, {etc}]
我有一个 C# 类,例如,
public class MyObject
{
public string A { get; set; }
public string B { get; set; }
}
现在,我想使用 JsonConvert.DeserializeObject
,但要将“foo”映射到 A 等等。我该怎么做呢?
最佳答案
您可以使用 JsonProperty
属性。
[JsonProperty("foo")]
public string A { get; set; }
关于c# - 如何在反序列化时使用 C# 中的 Json.Net 将名称重新映射到对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10580365/