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.