我从如下所示的 HTTP 请求接收到 JSON 字符串:
[
{
"size":590,
"location":"California",
"report":{
"Bob":[
null,
"12.0.250.0",
"20130228"
],
"Mary":[
null,
"2013-02-28.01",
"20130228"
],
"John":[
null,
"12.00",
"59123805"
]
}
},
{
"size":12348,
"location":"Florida",
"report":{
"Misty":[
null,
"65492.592",
"89216753"
],
"Billy":[
null,
"789208.w9",
"65320880"
],
"John":[
null,
"89.8056",
"75920889"
]
}
}
]
我试图反序列化的类的结构如下:
[DataContract]
public class DeserializedObject
{
[DataMember(Name = "size")]
public UInt64 Size { get; set; }
[DataMember(Name = "location")]
public string Location { get; set; }
[DataMember(Name = "report")]
public Dictionary<string, ReportData> Report { get; set; }
}
[CollectionDataContract]
public class ReportData : List<object>
{
public string a
{
get { return (string)this[0]; }
set { this[0] = (string)value; }
}
public string b
{
get { return (string)this[1]; }
set { this[1] = (string)value; }
}
public string c
{
get { return (string)this[2]; }
set { this[2] = (string)value; }
}
}
但是,当我尝试反序列化它时,报告始终为空。
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<DeserializedObject>));
List<DeserializedObject> list = serializer.ReadObject(stream) as List<DeserializedObject>;
反序列化 JSON 响应的“报告”部分的正确方法是什么?