[英]C# Parse JSON to Dictionary<string, List<string>
I have some JSON returned inthe format of : 我有一些JSON以格式返回:
[{
"Strains":[{
"Description":"String content"
}],
"Description":"String content"
}]
Where there is a one to many relationship between the Description and the Strains. 描述与菌株之间存在一对多关系的地方。 I want to parse this into a
Dictionary<string, List<string>>
, could somebody please advise what I should be looking at to achieve this? 我想将它解析为
Dictionary<string, List<string>>
,有人可以告诉我应该看到什么来实现这个目标吗?
Thanks. 谢谢。
EDIT: 编辑:
I've tried deserializing as such: 我已经尝试过反序列化:
JsonDeserializer des = new JsonDeserializer();
var foo = (List<Dictionary<string, object>>)des.DeserializeObject(json);
However, no joy. 但是,没有快乐。 I'm just having a play with JSON.net, to see if there's anything there that helps.
我只是在玩JSON.net,看看有什么帮助。
I think it's failing because technically it's not a straight cast to a Dictionary<string, object>
. 我认为它失败了,因为从技术上讲,它不是直接转换为
Dictionary<string, object>
。 The "Strains" property is an object, whilst the "Description" property could be mapped as a KeyValuePair
“Strains”属性是一个对象,而“Description”属性可以映射为
KeyValuePair
You'll need to deserialize this to an object. 您需要将其反序列化为对象。 Have you tried Json.NET ?
您是否尝试过Json.NET ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.