c# iterate through json

后端 未结 2 444
感动是毒
感动是毒 2021-01-29 03:04

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

相关标签:
2条回答
  • 2021-01-29 03:35

    Perhaps looping over the properties using JProperty, performs better?

        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));
        }
    
    0 讨论(0)
  • 2021-01-29 03:36

    You could try using Newtonsoft JSON Deserializer.

    For your case you could do something like this:

    1. Create a Track class with needed properties

    2. Apply DeserializeObject

      Track jsonObject = JsonConvert.DeserializeObject<Track >(json);
      
    3. Iterate over jsonObject

    0 讨论(0)
提交回复
热议问题