C#遍历JSON [英] c# iterate through json
本文介绍了C#遍历JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我正在使用C#开发Soundcloud下载器.借助SoundCloud API,我获得了播放列表的JSON字符串,其中包括许多曲目信息:
Currently I am working on a soundcloud downloader in C#. With the help of the SoundCloud API I get a JSON string of a playlist, which includes a lot of information of the tracks:
我尝试过:
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首曲目的播放列表.有没有办法使此迭代过程更快?
it worked but it needs about 20 secs to iterate through a playlist with only 2 tracks. Is there a way to make this iteration process faster?
推荐答案
您可以尝试使用 Newtonsoft JSON Deserializer .
对于您的情况,您可以执行以下操作:
For your case you could do something like this:
-
创建具有所需属性的Track类
Create a Track class with needed properties
应用DeserializeObject
Apply DeserializeObject
Track jsonObject = JsonConvert.DeserializeObject<Track >(json);
遍历jsonObject
Iterate over jsonObject
这篇关于C#遍历JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文