Json.Net uses $ref
along with $id
as metadata to preserve object references in JSON. So when it sees $ref
it assumes that property is not part of the actual JSON property set, but an internal identifier referring to a matching $id
somewhere else in the JSON. Since your usage of $ref
is different than what Json.Net expects to see, it is throwing an error.
UPDATE
In Json.Net version 6.0.4 and later, there is now a setting by which you can instruct the deserializer to treat these metadata properties as normal properties instead of consuming them. All you need to do is set the MetadataPropertyHandling
setting to Ignore
and then deserialize as usual.
var settings = new JsonSerializerSettings();
settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
var obj = JsonConvert.DeserializeObject<FormDefinitionList>(json, settings);
Prior to version 6.0.4, a workaround was needed to solve this issue. If you cannot upgrade to the lastest version of Json.Net, see my answer to a similar question for some possible solutions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…