/// this method would serialize object to JSON string
public string ToJSON()
{
using (MemoryStream memoryStream = new MemoryStream())
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(thi
jsonSerializer.WriteObject(memoryStream , this);
memoryStream .Position = 0;
StreamReader sReader = new StreamReader(memoryStream );
return sReader.ReadToEnd();
}
}
/// This method is used to deserialize the object from JSON Object
///
{
using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(thi
return (T)jsonSerializer.ReadObject(memoryStream );
}
}
public List
{
using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typ
return (List
}
}
/// this method serialized Typed List to JSON string
public string ConvertToJSONList
{
using (MemoryStream memoryStream = new MemoryStream())
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typ
jsonSerializer.WriteObject(memoryStream , ListT);
mStream.Position = 0;
StreamReader sReader = new StreamReader(memoryStream );
return sReader.ReadToEnd();
}
}
No comments:
Post a Comment