New features:
Added support for deserializing to an anonymous type with the DeserializeAnonymousType method. Support for reading, writing and serializing the new DateTimeOffset type. Added IsoDateTimeConverter. Converts DateTimes and DateTimeOffsets to and from the ISO 8601 format. Added JavaScriptDateTimeConverter. Converts DateTimes and DateTimeOffsets to and from a JavaScript date constructor. XmlNodeConverter handles serializing and deserializing JavaScript constructors. Ability to force XmlNodeConverter to write a value in an array. Logic is controlled by an attribute, json:Array="true". Changes: Dates are now serialized in a JSON complient manner, similar to ASP.NET's JavaScriptSerializer or WCF's DataContractJsonSerializer - http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx Removed the AspNetAjaxDateTimeConverter.
This commit is contained in:
@@ -34,8 +34,7 @@ using System.IO;
|
||||
|
||||
namespace Newtonsoft.Json.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class LinqToJsonTest
|
||||
public class LinqToJsonTest : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void ObjectParse()
|
||||
@@ -226,12 +225,16 @@ keyword such as type of business.""
|
||||
[Test]
|
||||
public void JTokenToStringTypes()
|
||||
{
|
||||
string json = @"{""Color"":2,""Establised"":new Date(1264118400000),""Width"":1.1,""Employees"":999,""RoomsPerFloor"":[1,2,3,4,5,6,7,8,9],""Open"":false,""Symbol"":""@"",""Mottos"":[""Hello World"",""öäüÖÄÜ\\'{new Date(12345);}[222]_µ@²³~"",null,"" ""],""Cost"":100980.1,""Escape"":""\r\n\t\f\b?{\\r\\n\""'"",""product"":[{""Name"":""Rocket"",""Expiry"":new Date(949532490000),""Price"":0},{""Name"":""Alien"",""Expiry"":new Date(-59011459200000),""Price"":0}]}";
|
||||
string json = @"{""Color"":2,""Establised"":new Date(1264118400000),""Width"":1.1,""Employees"":999,""RoomsPerFloor"":[1,2,3,4,5,6,7,8,9],""Open"":false,""Symbol"":""@"",""Mottos"":[""Hello World"",""öäüÖÄÜ\\'{new Date(12345);}[222]_µ@²³~"",null,"" ""],""Cost"":100980.1,""Escape"":""\r\n\t\f\b?{\\r\\n\""'"",""product"":[{""Name"":""Rocket"",""Expiry"":new Date(949532490000),""Price"":0},{""Name"":""Alien"",""Expiry"":new Date(-62135596800000),""Price"":0}]}";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
|
||||
Assert.AreEqual(@"""Establised"": new Date(1264118400000)", o.Property("Establised").ToString());
|
||||
Assert.AreEqual(@"new Date(1264118400000)", o.Property("Establised").Value.ToString());
|
||||
Assert.AreEqual(@"""Establised"": new Date(
|
||||
1264118400000
|
||||
)", o.Property("Establised").ToString());
|
||||
Assert.AreEqual(@"new Date(
|
||||
1264118400000
|
||||
)", o.Property("Establised").Value.ToString());
|
||||
Assert.AreEqual(@"""Width"": 1.1", o.Property("Width").ToString());
|
||||
Assert.AreEqual(@"1.1", o.Property("Width").Value.ToString());
|
||||
Assert.AreEqual(@"""Open"": false", o.Property("Open").ToString());
|
||||
@@ -271,13 +274,13 @@ keyword such as type of business.""
|
||||
JArray a =
|
||||
new JArray(
|
||||
o,
|
||||
new DateTime(2000, 10, 10),
|
||||
new DateTime(2000, 10, 10, 0, 0, 0, DateTimeKind.Utc),
|
||||
55,
|
||||
new JArray(
|
||||
"1",
|
||||
2,
|
||||
3.0,
|
||||
new DateTime(4, 5, 6, 7, 8, 9)
|
||||
new DateTime(4, 5, 6, 7, 8, 9, DateTimeKind.Utc)
|
||||
),
|
||||
new JConstructor(
|
||||
"ConstructorName",
|
||||
@@ -295,13 +298,13 @@ keyword such as type of business.""
|
||||
""Test3"": ""Test3Value"",
|
||||
""Test4"": null
|
||||
},
|
||||
new Date(971136000000),
|
||||
""\/Date(971136000000)\/"",
|
||||
55,
|
||||
[
|
||||
""1"",
|
||||
2,
|
||||
3,
|
||||
new Date(-59011459200000)
|
||||
""\/Date(-62030076711000)\/""
|
||||
],
|
||||
new ConstructorName(
|
||||
""param1"",
|
||||
|
||||
Reference in New Issue
Block a user