当前位置: 移动技术网 > IT编程>开发语言>.net > JSONHelper

JSONHelper

2018年12月06日  | 移动技术网IT编程  | 我要评论

解剖中华鲟惊现女尸,口交会传染性病吗?,桃花坞商城

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.io;
using system.text;
using system.web.script.serialization;



[serializable] public static class jsonhelper { /// <summary> /// 对象转json /// </summary> /// <param name="obj">对象</param> /// <returns>json格式的字符串</returns> public static string objecttojson(object obj) { javascriptserializer jss = new javascriptserializer(); try { return jss.serialize(obj); } catch { } return null; } /// <summary> /// /// json文本转对象,泛型方法 /// </summary> /// <typeparam name="t">类型</typeparam> /// <param name="jsontext">json文本</param> /// <returns>指定类型的对象</returns> public static t jsontoobject<t>(string jsontext) { javascriptserializer jss = new javascriptserializer(); try { return jss.deserialize<t>(jsontext); } catch{} return default(t); } public static string objecttojsondatetime(object obj) { javascriptserializer jss = new javascriptserializer(); jss.registerconverters(new javascriptconverter[] { new datetimeconverter() }); try { return jss.serialize(obj); } catch { } return null; } }


using system;
using system.collections;
using system.collections.generic;
using system.linq;
using system.text;
using system.web.script.serialization;
    


public class datetimeconverter : javascriptconverter
    {
        public override object deserialize(idictionary<string, object> dictionary, type type, javascriptserializer serializer)
        {
            return new javascriptserializer().converttotype(dictionary, type);
        }

        public override idictionary<string, object> serialize(object obj, javascriptserializer serializer)
        {
            if (!(obj is datetime))
            {
                return null;
            }
            return new customstring(((datetime)obj).tostring("yyyy-mm-dd hh:mm:ss"));
        }

        public override ienumerable<type> supportedtypes
        {
            get
            {
                return new[] { typeof(datetime) };
            }
        }

        private class customstring : uri, idictionary<string, object>
        {
            public customstring(string str) : base(str, urikind.relative)
            {
            }

            void idictionary<string, object>.add(string key, object value)
            {
                throw new notimplementedexception();
            }

            bool idictionary<string, object>.containskey(string key)
            {
                throw new notimplementedexception();
            }

            icollection<string> idictionary<string, object>.keys
            {
                get
                {
                    throw new notimplementedexception();
                }

            }

            bool idictionary<string, object>.remove(string key)
            {
                throw new notimplementedexception();
            }


            bool idictionary<string, object>.trygetvalue(string key, out object value)
            {
                throw new notimplementedexception();

            }

            icollection<object> idictionary<string, object>.values
            {

                get
                {
                    throw new notimplementedexception();
                }

            }

            object idictionary<string, object>.this[string key]
            {
                get
                {
                    throw new notimplementedexception();
                }
                set
                {
                    throw new notimplementedexception();
                }
            }

            void icollection<keyvaluepair<string, object>>.add(keyvaluepair<string, object> item)
            {
                throw new notimplementedexception();
            }

            void icollection<keyvaluepair<string, object>>.clear()
            {
                throw new notimplementedexception();
            }

            bool icollection<keyvaluepair<string, object>>.contains(keyvaluepair<string, object> item)
            {

                throw new notimplementedexception();

            }

            void icollection<keyvaluepair<string, object>>.copyto(keyvaluepair<string, object>[] array, int arrayindex)
            {
                throw new notimplementedexception();

            }

            int icollection<keyvaluepair<string, object>>.count
            {
                get
                {
                    throw new notimplementedexception();
                }
            }

            bool icollection<keyvaluepair<string, object>>.isreadonly
            {
                get
                {
                    throw new notimplementedexception();
                }
            }

            bool icollection<keyvaluepair<string, object>>.remove(keyvaluepair<string, object> item)
            {
                throw new notimplementedexception();
            }

            ienumerator<keyvaluepair<string, object>> ienumerable<keyvaluepair<string, object>>.getenumerator()
            {
                throw new notimplementedexception();
            }

            ienumerator ienumerable.getenumerator()
            {
                throw new notimplementedexception();
            }
        }
    }

  

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网