I have this kind of json structure:
{ "Root": { "data": [ { "CardName": "card1", "functions": [ { "State": "OPEN", "State": "INHERENT" } ] }, { "CardName": "card2", "functions": [ { "State": "CLOSED", "State": "INHERENT" } ] } ] } } And my C# classes are :
[DataContract] public class Card { [DataMember(Name = "CardName")] public string CardName { get; set; } [DataMember(Name = "functions")] public List<Function> Functions { get; set; } } [DataContract] public class Function { [DataMember(Name = "State")] public string State { get; set; } } I would like to parse that structure in order to get a list of cards, and each card containing a list of functions.
At this moment i am trying this:
string content = string.Empty; using (StreamReader sr = new StreamReader("json")) { string line; while ((line = sr.ReadLine()) != null) { content += line; } } List<Card> dynObj = JsonConvert.DeserializeObject<Card>(content); but i only get a list of nulls. Can you please tell me where the problem is ?