C# 遍历json

标签 c# json soundcloud

目前我正在用 C# 开发 soundcloud 下载器。在 SoundCloud API 的帮助下,我获得了播放列表的 JSON 字符串,其中包含轨道的大量信息:

http://pastebin.com/HfrjqyJE

我尝试过:

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/

相关文章:

c# - 使用 LINQ 表达式创建树

javascript - 循环遍历多层 json Jquery

javascript - Soundcloud 流媒体音频

javascript - Soundcloud iframe 小部件定制

javascript - 使用 DataTables 显示 JSON 对象

javascript - 如何通过 soundcloud API 创建公共(public)播放列表?

c# - '/' 应用程序中的服务器错误

c# - 在不创建新实例的情况下反射(reflect)嵌套实例

c# - 如何使用 EF 代码优先 POCO 创建 View

javascript - JSON 与动态编码