当前位置:网站首页>Can I specify a path in an attribute to map a property in my class to a child property in my JSON?

Can I specify a path in an attribute to map a property in my class to a child property in my JSON?

2022-07-07 04:46:00 French red wine sweet

problem :

There is some code (which I can't change) that uses Newtonsoft.Json's DeserializeObject<T>(strJSONData) to take data from a web request and convert it to a class object (I can change the class). There are some codes ( I can't change it ) Use Newtonsoft.Json Of DeserializeObject<T>(strJSONData) from Web Get the data in the request and convert it into a class object ( I can change the class ).By decorating my class properties with [DataMember(Name = "raw_property_name")] I can map the raw JSON data to the correct property in my class. By using [DataMember(Name = "raw_property_name")] Decorate my class properties , I can put the original JSON The data is mapped to the correct attributes in my class .Is there a way I can map the child property of a JSON complex object to a simple property? Is there any way to JSON The sub attributes of complex objects are mapped to simple attributes ?Here's an example: Here is an example :

{    "picture":     {        "id": 123456,        "data":         {            "type": "jpg",            "url": "http://www.someplace.com/mypicture.jpg"        }    }}

I don't care about any of the rest of the picture object except for URL, and so don't want to setup a complex object in my C# class. except URL, I don't care about any of the rest of the image object , So I don't want to be in my C# Set complex objects in class .I really just want something like: I really just want something like this :

[DataMember(Name = "picture.data.url")]public string ProfilePicture { get; set; }

Is this possible? Is that possible? ?


Solution :

Reference resources : https://stackoom.com/en/question/2Epos
原网站

版权声明
本文为[French red wine sweet]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130752267521.html

随机推荐