Parsing UTC Time in JSON.net -


i have json file have deserialized class created called mytype

jsonconvert.deserializeobject<mytype>(json); 

one of json properties time expressed in utc. take utc time , convert datetime object

datetime timestamp = datetime.parseexact(     jsontime, "o", cultureinfo.invariantculture, datetimestyles.roundtripkind); 

the above works fine when utc time is: 2014-06-25t00:30:07.9289078+00:00

but pukes on : 2014-06-24t00:31:08.62124+00:00

i suspect it's because of missing trailing "0"s before "+"

i playing around json.net , trying use jtoken.parse method seems doing want.

var t = newtonsoft.json.linq.jtoken.parse(       @"{ ""x"": ""2014-06-24t00:31:08.62124+00:00"" }").value<datetime>("x"); 

how jtoken.parse converting utc time correctly , how can use in jsonconvert.deserializeobject<mytype>(json); ?

i tried set

public static jsonserializersettings jsonserializersettings1 {     {      return new jsonserializersettings { dateparsehandling = dateparsehandling.datetime};   } } ....... return jsonconvert.deserializeobject<mytype>(json, jsonserializersettings1); 

it still not convert utc date time during deserialization

did try setting dateformathandling isodateformat , datetimezonehandling utc?

class program {     static void main(string[] args)     {         string json = @"{ ""date"": ""2014-06-24t00:31:08.62124+00:00"" }";          jsonserializersettings settings = new jsonserializersettings         {             dateformathandling = dateformathandling.isodateformat,             datetimezonehandling = datetimezonehandling.utc         };          mytype obj = jsonconvert.deserializeobject<mytype>(json, settings);          console.writeline(obj.date.tostring());     } }  class mytype {     public datetime date { get; set; } } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -