-Fixed JTokenWriter error with duplicate properties
This commit is contained in:
@@ -265,6 +265,28 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteDuplicatePropertyName()
|
||||
{
|
||||
JTokenWriter writer = new JTokenWriter();
|
||||
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WritePropertyName("prop1");
|
||||
writer.WriteStartObject();
|
||||
writer.WriteEndObject();
|
||||
|
||||
writer.WritePropertyName("prop1");
|
||||
writer.WriteStartArray();
|
||||
writer.WriteEndArray();
|
||||
|
||||
writer.WriteEndObject();
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""prop1"": []
|
||||
}", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateTimeZoneHandling()
|
||||
{
|
||||
|
||||
@@ -8630,11 +8630,11 @@ Path '', line 1, position 1.");
|
||||
[Test]
|
||||
public void DuplicatePropertiesInNestedObject()
|
||||
{
|
||||
ExceptionAssert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
string content = @"{""result"":{""time"":1408188592,""time"":1408188593},""error"":null,""id"":""1""}";
|
||||
JsonConvert.DeserializeObject<JObject>(content);
|
||||
}, "Can not add property time to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.");
|
||||
string content = @"{""result"":{""time"":1408188592,""time"":1408188593},""error"":null,""id"":""1""}";
|
||||
JObject o = JsonConvert.DeserializeObject<JObject>(content);
|
||||
int time = (int)o["result"]["time"];
|
||||
|
||||
Assert.AreEqual(1408188593, time);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user