Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DataContractJsonSerializer Class

Serializes objects to the JavaScript Object Notation (JSON) and deserializes JSON data to objects. This class cannot be inherited.

Namespace:  System.Runtime.Serialization.Json
Assembly:  System.ServiceModel.Web (in System.ServiceModel.Web.dll)
Visual Basic (Declaration)
Public NotInheritable Class DataContractJsonSerializer _
    Inherits XmlObjectSerializer
Visual Basic (Usage)
Dim instance As DataContractJsonSerializer
C#
public sealed class DataContractJsonSerializer : XmlObjectSerializer
Visual C++
public ref class DataContractJsonSerializer sealed : public XmlObjectSerializer
JScript
public final class DataContractJsonSerializer extends XmlObjectSerializer

Use the DataContractJsonSerializer class to serialize instances of a type into a JSON document and to deserialize a JSON document into an instance of a type. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in a JSON document for later retrieval. This JSON document can later be deserialized into the Person class or another class with an equivalent data contract.

If an error occurs during the serialization of an outgoing reply on the server or the reply operation throws an exception for some other reason, it may not get returned to the client as a fault.

System..::.Object
  System.Runtime.Serialization..::.XmlObjectSerializer
    System.Runtime.Serialization.Json..::.DataContractJsonSerializer
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
example      KitWest   |   Edit   |   Show History
using System;
using System.Windows.Forms;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
 
namespace ReadSomeJson
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
 
    private void button1_Click(object sender, EventArgs e)
{
DataContractJsonSerializer ser
= new DataContractJsonSerializer(typeof(Product));
using (FileStream fs = File.OpenRead(@"c:\jsonText.txt"))
{
//string json = @"{""Name"" : ""My Product""}";
//MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
Product product = ser.ReadObject(fs) as Product;
MessageBox.Show("Product Name: " + product.Name);
}
}
}
  
[Serializable]
public class Product
{
public string Name;
}
}
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker