You cannot get the original string, date strings are recognized and converted to DateTime structures inside JsonReader . You can see this if:
Console.WriteLine(((JValue)data["SimpleDate"]).Value.GetType());
You can, however, extract dates in ISO 8601 format by following these steps:
var value = JsonConvert.SerializeObject(data["SimpleDate"]);
This will always output JValue in a suitable JSON string format. Since your starting dates are in this format, this can satisfy your needs.
(Honestly, I'm surprised JValue.ToString() outputs dates in a format other than ISO, given that JObject.ToString() displays dates specified in ISO format.)
If you were able to change the settings while reading your JObject , you can use JsonSerializerSettings.DateParseHandling = DateParseHandling.None :
var settings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }; var data = JsonConvert.DeserializeObject<JObject>(@"{ ""SimpleDate"":""2012-05-18T00:00:00Z"", ""PatternDate"":""2012-11-07T00:00:00Z"" }", settings); var value = data["SimpleDate"].Value<string>(); Debug.WriteLine(value);
There is no overload in JObject.Parse() that accepts JsonSerializerSettings , so you will need to use DeserializeObject . This parameter ultimately extends to JsonReader.DateParseHandling .
dbc
source share