I’m targeting .net framework 4.7 with a winforms application. I started by following this article https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient so I am using DataContractJsonSerializer. I’m trying to learn about a REST interface that returns JSON -
{"Resource":
{"@attributes":
{"name":"Asset",
"resourceId":"Asset",
"type":"Resource"
}
}
}
I used netwonsoft.json 12.0.2 to paste the JSON as classes. It ignores the ‘@’ character and creates a member “attributes” in class “Resource” with type “Attributes” .
When DataContractJsonSerializer attempts to deserialise the JSON it skips the @attribute element, I presume because it does not match the class name.
Is there a way to map the element @attributes to my attributes member / class?
I have tried adding [DataMember(Name = "@attributes")] on the attributes member of the Resource class and a [DataContract(Name = "@attributes")] on the Attributes class but still the element appears to be skipped (attributes member of Resource is null).