How do deserialize this JSON into an object?

前端 未结 5 705
醉酒成梦
醉酒成梦 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:11

    the above code that you have for your classes looks correct on first glance.

    i've been successful with deserializing JSON with the following class(JavaScriptSerializer). used as follows

    using System.Web.Script.Serialization;
    
    JavaScriptSerializer js = new JavaScriptSerializer();
    string file = File.ReadAllText(filePath);
    MonthyPerformance json = js.Deserialize(file);
    

    oh, and add [Serializable] to your class attributes for each class

    [Serializable]
    class whatever{}
    

提交回复
热议问题