-Fixed JTokenWriter error with duplicate properties

This commit is contained in:
James Newton-King
2015-08-16 22:48:45 +12:00
parent ec23e08178
commit 6b02abe20c
4 changed files with 37 additions and 8 deletions
+9 -1
View File
@@ -166,9 +166,17 @@ namespace Newtonsoft.Json.Linq
/// <param name="name">The name of the property.</param>
public override void WritePropertyName(string name)
{
JObject o = _parent as JObject;
if (o != null)
{
// avoid duplicate property name exception
// last property name wins
o.Remove(name);
}
AddParent(new JProperty(name));
// don't set state until after in case of an error such as duplicate property names
// don't set state until after in case of an error
// incorrect state will cause issues if writer is disposed when closing open properties
base.WritePropertyName(name);
}