This post will discuss how to convert a JSON String to a JSON object in C#.

1. Using JsonSerializer.Deserialize() method

For .NET versions 4.7.2 and later, you can use the JsonSerializer.Deserialize() method for deserializing a JSON string. It parses the specified JSON string into a specified .NET type.

The following example illustrates. Note that the JsonSerializer class is included in the System.Text.Json namespace.

Download Code

2. Using Json.NET Library

Before .NET Framework 4.7.2, you can use the Json.NET library for deserializing a JSON. Its Newtonsoft.Json.JsonConvert.DeserializeObject() method accepts a JSON string to deserialize, and creates an instance of the object type, as specified by the generic parameter.

Download Code>

 
If you don’t need a typed object, you can do like:

Download Code

3. Using JavaScriptSerializer Class

For AJAX-enabled applications, you can use the JavaScriptSerializer class for deserialization of data objects. To deserialize a JSON string, you can use the Deserialize() or DeserializeObject() methods.

The following example provides a simple illustration of JavaScriptSerializer.DeserializeObject() method.

Download Code

That’s all about converting a JSON String to a JSON object in C#.