因此,我试图解析一些json数据。.我想"id"
从"owner"
字符串列表中的每个节点中获取所有,但是我似乎无法通过此操作访问节点。
string theData = File.ReadAllText("data.txt");
dynamic json = JObject.Parse(theData);
数据如下所示:https://hatebin.com/tqfvnp5ndgyn
我如何正确地"id"
从每个"owner"
节点获取所有的并将它们放在一个new List<string>
?
查看您的特定JSON对象是否适合LINQ查询。
例如:
https://www.newtonsoft.com/json/help/html/QueryingLINQtoJSON.htm
var postTitles =
from p in rss["channel"]["item"]
select (string)p["title"];
... 要么 ...
var categories =
from c in rss["channel"]["item"].SelectMany(i => i["categories"]).Values<string>()
group c by c
into g
orderby g.Count() descending
select new { Category = g.Key, Count = g.Count() };
以上示例中使用的源JSON:
string json = @"{
'channel': {
'title': 'James Newton-King',
'link': 'http://james.newtonking.com',
'description': 'James Newton-King\'s blog.',
'item': [
{
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
'description': 'Announcing the release of Json.NET 1.3, the MIT license and the source on CodePlex',
'link': 'http://james.newtonking.com/projects/json-net.aspx',
'categories': [
'Json.NET',
'CodePlex'
]
},
{
'title': 'LINQ to JSON beta',
'description': 'Announcing LINQ to JSON',
'link': 'http://james.newtonking.com/projects/json-net.aspx',
'categories': [
'Json.NET',
'LINQ'
]
}
]
}
}";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句