JavaScriptSerializer: Serialize objects


Sunday, August 23, 2020 Difficulty: Intermediate

Objective

Create a Java program that serialize and deserialize objects in JSON format. To do this, you can use the JavaScriptSerializer 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 JavaScriptSerializer 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


                    

Output


                    

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

BinaryFormatter: Binary serialization

Create a Java program to serialize and deserialize objects in binary format.

2

XmlSerialization: Serialize objects

Create a Java program to serialize and deserialize objects in XML format.

3

JavaScriptSerializer: Serialize objects

Create a Java program that serialize and deserialize objects in JSON format.

4

DataContractJsonSerializer: Serialize objects

Create a Java program that serialize and deserialize objects in JSON format.

5

Newtonsoft.Json: Serialize objects

Create a Java program to serialize and deserialize objects in JSON format.

Data serialization

Practice with exercises in Java to serialize arrays or objects in different ways. Learn how to serialize and deserialize the information later.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play