serialize/deserialize List to JSON

后端 未结 1 858
野的像风
野的像风 2021-02-10 01:21

I want to be able to serialize/deserialize a generic list what I so far is this

    public static string ToJson(this object obj, int recursionDepth = 100) 
    {         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-02-10 02:14

    Try this on for size:

    public static T ToObject(this string obj, int recursionDepth = 100)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.RecursionLimit = recursionDepth;
        return serializer.Deserialize(obj);
    }
    

    Then use it like this:

    mystring.ToObject>();
    

    0 讨论(0)
提交回复
热议问题