目前我正在用 C# 开发 soundcloud 下载器。在 SoundCloud API 的帮助下,我获得了播放列表的 JSON 字符串,其中包含轨道的大量信息:
我尝试过:
JObject results = JObject.Parse(e.Result);
foreach (var result in results["tracks"])
{
string streamUrl = (string)result["stream_url"];
string title = (string)result["title"];
}
它有效,但需要大约 20 秒来迭代只有 2 首轨道的播放列表。有没有办法让这个迭代过程更快?
最佳答案
也许使用 JProperty 循环属性性能更好?
string json = "{a: 10, b: 'aaaaaa', c: 1502}";
JObject parsedJson = JObject.Parse(json);
foreach (JProperty property in parsedJson.Properties())
{
Console.WriteLine(string.Format("Name: [{0}], Value: [{1}].", property.Name, property.Value));
}
关于C# 遍历json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31539656/