コード例 #1
0
    public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
    {
        SillyObject se = (SillyObject)obj;
        Dictionary <string, object> objs = new Dictionary <string, object>();

        if (!String.IsNullOrEmpty(se.SomeOtherProperty))
        {
            objs.Add("SomeOtherProperty", se.SomeOtherProperty);
        }
        return(objs);
    }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        JavaScriptSerializer jsonSer = new JavaScriptSerializer();

        jsonSer.RegisterConverters(new JavaScriptConverter[] { new SillyConverter() });
        string json = jsonSer.Serialize(new SillyObject());

        Response.Write(json);

        SillyObject obj = jsonSer.Deserialize <SillyObject>(json);

        Response.Write(obj.SomeOtherProperty);
    }
コード例 #3
0
    public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
    {
        SillyObject se = new SillyObject();

        foreach (string key in dictionary.Keys)
        {
            switch (key)
            {
            case "SomeOtherProperty":
                se.SomeOtherProperty = dictionary[key].ToString();
                break;
            }
        }
        return(se);
    }