如何使用JSON.NET反序列化到嵌套/递归字典和列表?递归、嵌套、如何使用、字典

2023-09-02 21:25:20 作者:脑洞开大发惹

我要反序列化一个复杂的JSON BLOB成标准的.NET容器使用在code表示不知道的JSON 。该公司预计的事情是在标准的.NET类型,特别是词典[字符串对象]或列表[对象]这里的对象可以是原始的或递归(词典或列表)。

I need to deserialize a complex JSON blob into standard .NET containers for use in code that is not aware of JSON. It expects things to be in standard .NET types, specifically Dictionary[string, object] or List[object] where "object" can be primitive or recurse (Dictionary or List).

我不能用静态类型映射的结果和JObject / JToken不适合。理想的情况下,会有一些方法(通过合同吧?),以原始JSON转换成基本的.NET容器。

I cannot use a static type to map the results and JObject/JToken don't fit. Ideally, there would be some way (via Contracts perhaps?) to convert raw JSON into basic .NET containers.

我已经寻遍了所有的方式哄JSON.NET解串器到创造这些简单类型遇到时,{}或[],但收效甚微。

I've search all over for any way to coax the JSON.NET deserializer into creating these simple types when it encounters "{}" or "[]" but with little success.

任何帮助AP preciated!

Any help appreciated!

推荐答案

您不能做什么,我是问。至少没有,据我可以经过大量的研究证明。我不得不编辑Json.NET的源

You cannot do what I was asking. At least not as far as I can tell after MUCH research. I had to edit the source of Json.NET.