我想从PubMed获得稿件摘要。每个摘要的内容都采用JSON格式,格式如下。 " 29498802"是一个唯一的ID,每个手稿都有所不同。
{
"header":{
"type":"esummary",
"version":"0.3"
},
"result":{
"uids":[
"29498802"
],
"29498802":{
"uid":"29498802",
"pubdate":"2018 Mar 2",
"epubdate":"2018 Mar 2",
...
}
}
}
我在C#中使用Newtonsoft.Json将JSON反序列化为类:
var summary = JsonConvert.DeserializeObject<Summary>(stringResult);
我的摘要课程如下:
public class Summary
{
[JsonProperty("header")]
public Header header { get; set; }
[JsonProperty("result")]
public Result result { get; set; }
}
public class Result
{
[JsonProperty("uids")]
public List<string> uids { get; set; }
public Dictionary<string, PubMedId> content { get; set; }
}
public class PubMedId
{
[JsonProperty("uid")]
public string uid { get; set; }
...
}
我能够提取&#34;标题(类型和版本)&#34;,&#34; uids&#34;,但&#34;内容&#34;永远是空的。有什么建议吗?
答案 0 :(得分:2)
var summary = JsonConvert.DeserializeObject<Summary>(text);
var resultjO = JObject.Parse(text).Value<JObject>("result");
var pubdAsJObject = resultjO.Value<JObject>(summary.result.uids[0]);
var pubMed = JsonConvert.DeserializeObject<PubMedId>(pubdAsJObject.ToString());