O'Reilly logo

Windows Application Development Cookbook by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading a JSON file

Parsing the JSON-formatted content into an object or a collection of objects is significantly simplified using the Newtonsoft.Json library, as you will see in this recipe. Thus, you can convert a JSON-formatted string to the target type with just a single line of code, using the DeserializeObject method, as shown in the following line:

    variable = JsonConvert.DeserializeObject<type>(encoded-string) 

As an example, you will modify the project from the previous recipe by adding a Load button. Once you click on it, the content of the Employees.json file will be loaded and parsed into a collection of EmployeeViewModel instances. Then, the result will be presented in the user interface.

Getting ready

To step through this recipe, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required