example: a Customer class have 100 data member(id, name, age, address...etc) to be serialization to JSON.

In Config file such as Web.config, can set a output list to serialize JSON ouptut.

If output only id and name, then JSON only have id and name.

My Question: Can support dynamic DataMember in a DataContract ?

有帮助吗?

解决方案

You mean optional datamembers, I guess so, check this question Surely you'll have to have null values for the ones you dont want to send over the wire. Another, more dirtier, solution would be to use a dictionary as a datamember and have the fields you want to send as elements there. There may be type conversion issues, but maybe it serves you better.

Edit:

You probably want to go with a dictioray serialized as an associative array en js, as this question specifies. Check the answers and the links in there. That should get you going. But still I'd go with optional datamembers since it's more of a "contract" thing. Other than that a better description of what you want to do will help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top