我通过将 Kinect v2 中的 Body 类转换为 List 并将数据保存在文本文件中来序列化它。但是当我将它反序列化回 List 对象时,我无法做到这一点。它说“无法找到用于 Microsoft.Kinect.Body 类型的构造函数。一个类应该有一个默认构造函数、一个带参数的构造函数或一个标有 JsonConstructor 属性的构造函数”。我正在使用以下代码。
List<Body> newbodies = new List<Body>();
newbodies = JsonSerialization.ReadFromJsonFile<List<Body>> ("skeletonData.txt");
public static T ReadFromJsonFile<T>(string filePath) where T : new()
{
TextReader reader = null;
try
{
reader = new StreamReader(filePath);
var fileContents = reader.ReadToEnd();
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(fileContents);
}
finally
{
if (reader != null)
reader.Close();
}
}