Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

JSON.Net - Change $type field to another name?

When using Json.Net, I understand how to get the $type property into the rendered json, but is there a way to change that field name? I need to use "__type" instead of "$type".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

http://json.codeplex.com/workitem/22429

"I would rather keep $type hard coded and consistent."

Consistent with what I wonder?

http://json.codeplex.com/workitem/21989

I would rather not - I think this is too specific to me and I don't want to go overboard with settings. At some point I will probably implement this - http://json.codeplex.com/workitem/21856 - allowing people to read/write there own meta properties in the JSON and you could reimplement type name handling with a new property name. The other option is just to modify the source code for yourself to have that property name.

And more recently, Issue #36: Customizable $type property name feature:

I'd rather not

This is my solution...

json.Replace(""$type": "", ""type": "");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...