问题描述
使用Json.Net时,我了解如何将$ type属性获取到呈现的json中,但是有没有办法更改该字段名称?我需要使用"__type"而不是"$ type".
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".
推荐答案
不幸的是,在内部静态类Newtonsoft.Json.Serialization.JsonTypeReflector
中,类似这样的代码硬编码为public const string TypePropertyName = "$type";
.
Looks like this is hardcoded as public const string TypePropertyName = "$type";
in Newtonsoft.Json.Serialization.JsonTypeReflector
which is internal static class unfortunately.
我自己需要这个,而我唯一能想到的就是拥有json.net本身的定制修改版本.当然,这是一个主要的皮塔饼.
I needed this myself, and the only thing I can think of is having custom modified version of json.net itself. Which is of course is a major pita.
这篇关于JSON.Net-将$ type字段更改为另一个名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!