We are getting similar response from one of 3rd party API providers:
{
"$id" : "1",
"$values" : [
{
"$id" : "2",
"Description": "Description"
"$values" : [
{
"$id" : "1",
"IntProperty" : 6,
"StringProperty" : "Test 1",
"DecimalProperty" : 11.23
},
{
"$id" : "2",
"IntProperty" : 7,
"StringProperty" : "Test 2",
"DecimalProperty" : 12.23
},
{
"$id" : "3",
"IntProperty" : 8,
"StringProperty" : "Test 3",
"DecimalProperty" : 11.24
}
]
}
]
}
As you can see for some reason they are using "$id" to provide db id to the API user. However, when JSON.net attempts to deserialize such string it is reading "$id" as object reference. I tried to use JsonProperty attribute as well as PreserveReferencesHandling.None and TypeNameHandling.All but this doesn't seem to work. Is there any other option than do a string.Replace("\"$id\"", "\"id\"")?
Data structure I'm trying to convert it to:
public class RootObject
{
[JsonProperty( PropertyName = "$id" )]
public string Id { get; set; }
[JsonProperty( PropertyName = "$values" )]
public List<ChildObject> Values { get; set; }
}
public class ChildObject
{
[JsonProperty( PropertyName = "$id" )]
public string Id { get; set; }
public string Description { get; set;}
[JsonProperty( PropertyName = "$values" )]
public List<ChildObject1> Values { get; set; }
}
public class ChildObject1
{
JsonProperty( PropertyName = "$id" )]
public string Id { get; set; }
public int IntProperty { get; set; }
public string StringProperty { get; set;}
public decimal DecimalProperty { get; set;}
}