日期:2014-05-20 浏览次数:20856 次
private T JsonToObject<T>(string jsonStr)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonStr));
T jsonObject = (T)ser.ReadObject(ms);
ms.Close();
return jsonObject;
}
private void Form1_Load(object sender, EventArgs e)
{
string jsonString1 = @"{""Description"":""this is a test"",""Enable"":""false"",""Title"":""test""}";
TestClass t1 = JsonToObject<TestClass>(jsonString1);
}
private T JsonToObject<T>(string jsonStr)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonStr));
T jsonObject = (T)ser.ReadObject(ms);
ms.Close();
return jsonObject;
}