The JSON is:
{"date":13,"day":5,"hours":19,"minutes":6,"month":10,"nanos":0,"seconds":41,"time":1605265601000,"timezoneOffset":-480,"year":120}
When I try to Convert to DateTime, I encountered the following error:
Newtonsoft.Json.JsonReaderException HResult=0x80131500 Message=Unexpected character encountered while parsing value: {. Path '', line 1, position 1. Source=Newtonsoft.Json StackTrace: at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType) at Newtonsoft.Json.JsonTextReader.ReadAsDateTime() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at test.Program.Main(String[] args) in E:\code\UI\test\Program.cs:line 77
My Code:
var txt = "{\"date\":13,\"day\":5,\"hours\":19,\"minutes\":6,\"month\":10,\"nanos\":0,\"seconds\":41,\"time\":1605265601000,\"timezoneOffset\":-480,\"year\":120}";
var aa = Newtonsoft.Json.JsonConvert.DeserializeObject<DateTime>(txt);
Console.ReadKey();
when I use Newtonsoft.Json.dll 3.5 version instead, the error disappears. when I use Newtonsoft.Json.dll 9.0 version instead, the error appears.
I'm using VS2017 to Build, where is my Error?
saleTimeproperty which does not exist inDateTimesaleTimetext, I'm also try to create a class by DateTime property,like thispublic class DateTest { public DateTime saleTime { get; set; } }, and deserialize code modify to this : ` var aa = Newtonsoft.Json.JsonConvert.DeserializeObject<DateTest>(txt); `, the error also exists