Primarily; I use Newtonsoft.Json to deserialize JSON in such objects:
JSON:
[{"number":22041}]
Order Object
[JsonProperty("number")] public string OrderNumber { get; set; }
However, depending on which version the "other" side is included in, Json may change to
[{"order_number":22041}]
Therefore, I would like to predefine "number" and "pc_number" for both deserialization in my order number.
Is there a way to achieve something like the following (which actually works)
[JsonProperty("order_number")] [JsonProperty("number")] public string OrderNumber { get; set; }
I could write another class that has the same properties, but with different JsonProperties depending on the version in which they are located, but it seems like trying something for the last time, if there is no possible way to make it easier.
Refresh
I agree that this question is a duplicate of the question above. However, since the given keys in JSON change significantly, I will create duplicate objects (for example, OrderV1, OrderV2).
Just replacing some characters with others will not be enough in my case .
source share