我从 2 个来源获得了一些数据。其中之一是将所需的数据作为子 json 发送。
"Shifts": [
{
"Shift": {
"ShiftID": 126604,
"Name": "Volunteers - High Intensity",
"Description": "sfsd",
"Venue": "",
"StartDateTime": "2014-01-28T12:00:00",
"EndDateTime": "2014-01-28T16:30:00",
"LocationN": "0.0",
"LocationE": "0.0"
}
}
]
与其他来源相比深一层:
"Shifts": [
{
"ShiftID": 126604,
"Name": "Volunteers - High Intensity",
"Description": "sfsd",
"Venue": "",
"StartDateTime": "2014-01-28T12:00:00",
"EndDateTime": "2014-01-28T16:30:00",
"LocationN": "0.0",
"LocationE": "0.0"
}
]
我正在阅读这段代码:
var shiftProperty = json.GetValue("Shifts");
if (shiftProperty != null)
{
ObservableCollection<Shift> shift = new ObservableCollection<Shift>();
MemoryStream memorystream = new MemoryStream(Encoding.UTF8.GetBytes(shiftProperty.ToString()));
DataContractJsonSerializer serializer = new DataContractJsonSerializer(shift.GetType());
shift = serializer.ReadObject(memorystream) as ObservableCollection<Shift>;
App.RootFrame.Dispatcher.BeginInvoke(() =>
{
Shifts = shift;
});
}
如何以与读取 2nd 格式相同的方式读取 1st 格式的数据?