我有这种json结构:
{
"Root": {
"data": [
{
"CardName": "card1",
"functions": [
{
"State": "OPEN",
"State": "INHERENT"
}
]
},
{
"CardName": "card2",
"functions": [
{
"State": "CLOSED",
"State": "INHERENT"
}
]
}
]
}
}
我的 C# 类是:
[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; }
}
我想解析该结构以获得卡片列表,并且每张卡片都包含一个函数列表。
此刻我正在尝试这个:
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);
但我只得到一个空值列表。你能告诉我问题出在哪里吗?