public class RootObject
{
[JsonProperty("585709" )]
public List<SummonerId> SummonerId { get; set; }
}
I have a class that uses the JsonProperty["585709"] for my JSON Api call. This is exactly what I want but.. the problem I am facing is , The property has to change according to the User's Id number.
What I've tried :
This seems to work however when the Json call is made the value searches for the original value "585709".
public class CustomDataContractResolver : DefaultContractResolver
{
public static readonly CustomDataContractResolver Instance = new CustomDataContractResolver();
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
if (property.DeclaringType == typeof(RootObject))
{
if (property.PropertyName.Equals("585709", StringComparison.OrdinalIgnoreCase))
{
property.PropertyName = "569099";
}
}
return property;
}
}
var prop = JsonConvert.SerializeObject(r, new JsonSerializerSettings { ContractResolver = CustomDataContractResolver.Instance });
var root = JsonConvert.DeserializeObject<RootObject>(request)
Is there a way I can change the value of JsonProperty for the Class?