-Fix JContainer child ordering when adding multi values

This commit is contained in:
JamesNK
2008-10-10 20:02:05 +00:00
parent 3038a8d79e
commit 68af212cfb
2 changed files with 56 additions and 1 deletions
@@ -298,5 +298,60 @@ Parameter name: index")]
string json = @"{""prop"":""value""}";
JArray.Parse(json);
}
public class ListItemFields
{
public string ListItemText { get; set; }
public object ListItemValue { get; set; }
}
[Test]
public void ArrayOrder()
{
string itemZeroText = "Zero text";
IEnumerable<ListItemFields> t = new List<ListItemFields>
{
new ListItemFields { ListItemText = "First", ListItemValue = 1 },
new ListItemFields { ListItemText = "Second", ListItemValue = 2 },
new ListItemFields { ListItemText = "Third", ListItemValue = 3 }
};
JObject optionValues =
new JObject(
new JProperty("options",
new JArray(
new JObject(
new JProperty("text", itemZeroText),
new JProperty("value", "0")),
from r in t
orderby r.ListItemValue
select new JObject(
new JProperty("text", r.ListItemText),
new JProperty("value", r.ListItemValue.ToString())))));
string result = "myOptions = " + optionValues.ToString();
Assert.AreEqual(@"myOptions = {
""options"": [
{
""text"": ""Zero text"",
""value"": ""0""
},
{
""text"": ""First"",
""value"": ""1""
},
{
""text"": ""Second"",
""value"": ""2""
},
{
""text"": ""Third"",
""value"": ""3""
}
]
}", result);
}
}
}
+1 -1
View File
@@ -227,7 +227,7 @@ namespace Newtonsoft.Json.Linq
foreach (object c in enumerable)
{
AddInternal(isLast, multiPrevious, c);
multiPrevious = (previous != null) ? previous._next : Last;
multiPrevious = (multiPrevious != null) ? multiPrevious._next : Last;
}
}
else