Hi everyone i have a problem with my json serealization. I\'m using the Json.NET package under Unity: I\'m searching to make a Database, editable on my application and store
Best way would be to configure JSON.Net to replace the default values by
JsonSerializerSettings jsSettings = new JsonSerializerSettings
{
ObjectCreationHandling = ObjectCreationHandling.Replace,
};
JsonConvert.DeserializeObject<Army>(jsonString, jsSettings);
The reason this is happening is due to the combination of two things:
To fix this, you can either change your code such that your constructors do not automatically add default items to your lists, or you can configure Json.Net to replace the lists on deserialization rather than reusing them. The latter by can be done by changing the ObjectCreationHandling setting to Replace as shown below:
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
var database = JsonConvert.DeserializeObject<Database>(www.text, settings);