using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;

namespace System.Collections
{
    public static class HashtableEx
    {
        static JavaScriptSerializer serializer = new JavaScriptSerializer();
        /// <summary>
        /// 添加到Hashtable并转为json
        /// </summary>
        /// <param name="h"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Hashtable AddJson(this Hashtable h, object key, object value)
        {
            h.Add(key, serializer.Serialize(value));
            return h;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="Result"></typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static Result JsonToModel<Result>(this string s)
        {
            return serializer.Deserialize<Result>(s);
        }
    }
}
