1. Course
  2. Data serialization
  3. DataContractJsonSerializer: Serialize objects

DataContractJsonSerializer: Serialize objects


Last updated: 8/23/2020 Difficulty: Intermediate

Create a C# program that serialize and deserialize objects in JSON format. To do this, you can use the DataContractJsonSerializer class included in the System.Web.Extensions namespace.

First implement a Person class with three properties (Name, Age and City). The City class will have two properties (Name and Population). Then create a person object and use the serializer of the DataContractJsonSerializer object to save the data in file.json, later deserialize the file.json and print it on the screen. Remember to prepare a ToString() method to print the Person class.

Input

  1.  

Output

  1.  

Solution

Data serialization

4 / 5

Android App


Practice C# anywhere with the free app for Android devices.

Android App

Exercises C# by difficulty


Learn C# at your own pace, the exercises are ordered by difficulty.

Make a donation


Your donations support our work and contribute to the maintenance of the app.

Advertising


CookieOwn and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.