转化json

/// <summary>
        /// 转换成JSON字符串
        /// </summary>
        /// <param name="jsonObject"></param>
        /// <returns></returns>
        public static string stringify(object jsonObject)
        {
            try
            {
                using (var ms = new MemoryStream())
                {
                    new DataContractJsonSerializer(jsonObject.GetType()).WriteObject(ms, jsonObject);
                    return Encoding.UTF8.GetString(ms.ToArray());
                }
            }
            catch (Exception E)
            {
                Log4Net.Error("转换JSON字符串异常 : " + E.Message);
                return string.Empty;
            }
        }
using System.Runtime.Serialization.Json;

 

posted on 2014-11-12 13:47  幻梦飞羽  阅读(151)  评论(0编辑  收藏  举报