-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Windows Application Development Cookbook
By :
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.
To step through this recipe, you need the project from the previous recipe.
To modify the preceding example to support loading data of employees from a JSON-formatted file, perform the following steps:
Add the Load button to the page by modifying the content...