string json = \"{\\\"People\\\":[{\\\"FirstName\\\":\\\"Hans\\\",\\\"LastName\\\":\\\"Olo\\\"}
{\\\"FirstName\\\":\\\"Jimmy\\\",\\\"LastName\
I use this JSON Helper class in my projects. I found it on the net a year ago but lost the source URL. So I am pasting it directly from my project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
///
/// JSON Serialization and Deserialization Assistant Class
///
public class JsonHelper
{
///
/// JSON Serialization
///
public static string JsonSerializer (T t)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream();
ser.WriteObject(ms, t);
string jsonString = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return jsonString;
}
///
/// JSON Deserialization
///
public static T JsonDeserialize (string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)ser.ReadObject(ms);
return obj;
}
}
You can use it like this: Create the classes as Craig W. suggested.
And then deserialize like this
RootObject root = JSONHelper.JsonDeserialize(json);