You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
815 B
30 lines
815 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.IO;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Text;
|
|
|
|
namespace OT.Web.Ap_Code
|
|
{
|
|
public class JsonHelper
|
|
{
|
|
public static T parse<T>(string jsonString)
|
|
{
|
|
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
|
|
{
|
|
return (T)new DataContractJsonSerializer(typeof(T)).ReadObject(ms);
|
|
}
|
|
}
|
|
|
|
public static string stringify(object jsonObject)
|
|
{
|
|
using (var ms = new MemoryStream())
|
|
{
|
|
new DataContractJsonSerializer(jsonObject.GetType()).WriteObject(ms, jsonObject);
|
|
return Encoding.UTF8.GetString(ms.ToArray());
|
|
}
|
|
}
|
|
}
|
|
}
|