Deserializing JSON data to C# using JSON.NET

前端 未结 7 1831
离开以前
离开以前 2020-11-22 04:01

I\'m relatively new to working with C# and JSON data and am seeking guidance. I\'m using C# 3.0, with .NET3.5SP1, and JSON.NET 3.5r6.

I have a defined C# class that

7条回答
  •  借酒劲吻你
    2020-11-22 04:38

    You can try checking some of the class generators online for further information. However, I believe some of the answers have been useful. Here's my approach that may be useful.

    The following code was made with a dynamic method in mind.

    dynObj = (JArray) JsonConvert.DeserializeObject(nvm);
    
    foreach(JObject item in dynObj) {
     foreach(JObject trend in item["trends"]) {
      Console.WriteLine("{0}-{1}-{2}", trend["query"], trend["name"], trend["url"]);
     }
    }
    

    This code basically allows you to access members contained in the Json string. Just a different way without the need of the classes. query, trend and url are the objects contained in the Json string.

    You can also use this website. Don't trust the classes a 100% but you get the idea.

提交回复
热议问题