如何使用 JSON.NET 反序列化为嵌套/递归字典和列表? [英] How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?
问题描述
我需要将复杂的 JSON blob 反序列化为标准 .NET 容器,以便在不知道 JSON 的代码中使用.它期望事物是标准的 .NET 类型,特别是 Dictionary
或 List
其中object"可以是原始的或递归的(Dictionary 或 List).
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.
感谢任何帮助!
推荐答案
你不能按照我的要求去做.至少在经过大量研究后我可以说不是.我不得不编辑 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.
这篇关于如何使用 JSON.NET 反序列化为嵌套/递归字典和列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!