[英]In C# - How do I ignore all the attributes with the postfix Specified generated by xsd while serializing and deserializing using json.net
[英]How do I remap names to object properties when deserializing, using Json.Net in C#
案例:我從第三方服務器收到一個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; }
您可以使用裝飾在屬性上的JsonPropertyAttribute
,為其指定應在JSON消息中找到的參數的名稱。 如果您不想使用屬性,也可以使用自定義JsonConverter 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.