1

I have serialized the Body class in Kinect v2 by converting it into List and saved the data in a text file. But when I deserialize it back to the List object, I am not able to do it. It says"Unable to find a constructor to use for type Microsoft.Kinect.Body. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute". I am using the following code.

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();
 }
}
  • Json.net cannot deserialize class without default constructor, or with several non-default constructors none of which is marked with `JsonConstructor` attribute. See details: http://stackoverflow.com/questions/41870132/how-does-json-deserialization-in-c-sharp-work/41871975#41871975 – Sergey Berezovskiy Mar 13 '17 at 11:29
  • By converting into List, it worked for serialization part. But how to deserialize it to get the object back? Is there a way? – Nagesh Naik Mar 13 '17 at 12:25

0 Answers0