How do deserialize this JSON into an object?

前端 未结 5 676
醉酒成梦
醉酒成梦 2021-01-14 02:36

I\'m trying to use JSON.Net to deserialize a JSON object into a C# object.

The object I want to create is MonthlyPerformance which contains a list of

5条回答
  •  别那么骄傲
    2021-01-14 03:34

    This is what I use for JSON deserialization...

    using System.Web.Script.Serialization;
    
    namespace blahblah
    {
        public partial class AccessTierService : ServiceBase
        {
            public static T ia_deserialize_json(string json_string)
            {
                try
                {
                    if ((String.Compare(json_string, null) == 0) ||
                        (String.Compare(json_string, "") == 0) ||
                        (String.Compare(json_string, String.Empty) == 0))
                    {
                        return default(T);
                    }
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return (T)serializer.Deserialize(json_string);
                }
                catch (Exception)
                {
                    return default(T);
                }
            }
        }
    }
    

    and to call it...

    login_request = ia_deserialize_json(body_string);
    

提交回复
热议问题