User mapping with Json.NET

I am trying to display JSON that looks like

"ids": {
    "id": {
        "@value":"6763754764235874140"
    }
}

And I would like to map it to a couple of classes that look like

class Property
{
    public Ids Ids { get; set; }
}

class Ids
{
    public string Id { get; set; }
}

So basically I want to write the value ids/id/@valuefrom the JSON document to Ids.Idin the class architecture. From looking at the documentation, I thought I could use something like

[JsonProperty(ItemConverterType=typeof(IdConverter))]
public string Id { get; set; }

and provide a custom subclass JsonConverternamed IdConverter. However, when I do this, mine IdConverter.ReadJsonwill never be called. What am I doing wrong?

+5
source share
1 answer

Looks like the answer was that it was ItemConverterTypedesigned to convert elements to an array. Double annotating properties with attributes JsonPropertyand JsonConverterworks:

[JsonProperty(PropertyName="id")]
[JsonConverter(typeof(IdConverter))]
public string Id { get; set; }
+13

All Articles