From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Basic JSON query techniques

Basic JSON query techniques

- [Instructor] JSON markup is a very popular format, so it is reasonable to want to query our JSON data with Linq. We can do that. We just have to add an additional NuGet package. In this example, I will right-click and choose References and Properties, and you can see that I've added a reference to Newtonsoft.Json. The way I did that is I clicked on Add NuGet. I went online and searched for Newtonsoft.Json and added it to the query. The other thing that I did to make my life a little bit simpler is in the namespace imports, I added the Newtonsoft.Json.Linq namespace. Once I do that, then I can start working with objects like this JObject. So let's take a look at the code we have here. On line two through nine, I'm declaring a string that contains some JSON. It's got a cards array, and then some individual items, cardName, team, and price. There's four of those cards. So the first thing I need to do is get the information. So since this isn't a string, I'll call JObject.Parse, pass in…

Contents