.NET API Browser

Namespace: System.Runtime.Serialization.Json

Summary

This namespace contains types that enable JSON serialization and deserialization for .NET objects. It provides classes to work with JSON data in a structured and object-oriented manner.

Classes

Interfaces

Structures

Enums

Example Usage

Here's a basic example of how to serialize a .NET object to JSON:

using System; using System.Runtime.Serialization.Json; using System.IO; using System.Text; public class Person { public string Name { get; set; } public int Age { get; set; } } public class Example { public static void Main(string[] args) { var person = new Person { Name = "Alice", Age = 30 }; var serializer = new DataContractJsonSerializer(typeof(Person)); using (var stream = new MemoryStream()) { serializer.WriteObject(stream, person); stream.Position = 0; using (var reader = new StreamReader(stream, Encoding.UTF8)) { // Output: {"Name":"Alice","Age":30} Console.WriteLine(reader.ReadToEnd()); } } } }