12345678910111213141516171819202122232425262728293031323334353637 |
- using System.Text;
- using System.IO;
- namespace EasyModbusClient.businessBody
- {
- //class JsonDataContractJsonSerializer
- //{
- // /// <summary>
- // /// 内存对象转换为json字符串
- // /// </summary>
- // /// <param name="obj"></param>
- // /// <returns></returns>
- // public static string ObjectToJson(object obj)
- // {
- // DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
- // MemoryStream stream = new MemoryStream();
- // serializer.WriteObject(stream, obj);
- // byte[] dataBytes = new byte[stream.Length];
- // stream.Position = 0;
- // stream.Read(dataBytes, 0, (int)stream.Length);
- // return Encoding.UTF8.GetString(dataBytes);
- // }
- // /// <summary>
- // /// Json字符串转内存对象
- // /// </summary>
- // /// <param name="jsonString"></param>
- // /// <param name="obj"></param>
- // /// <returns></returns>
- // public static object JsonToObject(string jsonString, object obj)
- // {
- // DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
- // MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
- // return serializer.ReadObject(mStream);
- // }
- //}
- }
|