Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Deserializing into DateTime works on sim but not on device

$
0
0

Hi all,

I am pulling an object via JSON from a web service. Dates and times are in a format similar to this: "2014-03-07T17:00:00". I am using Json.NET to deserialize the object which stores the dates into DateTime objects, which works perfectly fine in the simulator - but when I run the code on the device, I get really bizarre DateTime objects. Here is some relevant code for consideration.

protected IList<T> GetList<T>(string action)
{
    try
    {
                string content = this.WebClient.DownloadString(this.WebApiServiceUri + action);
                Console.WriteLine("WebService content received: {0}", content);
                return JsonConvert.DeserializeObject<IList<T>>(content, this.JsonSerializerSettings);
    }
    catch (WebException ex)
    {
        throw new WebServiceException(ex);
    }
}

For JsonSerializerSettings I've tried...

    //var format = "yyyy-MM-ddTHH:mm:ss";
    var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = "o" };

    this.JsonSerializerSettings = new JsonSerializerSettings()
    { 
            NullValueHandling = NullValueHandling.Ignore,
            Converters = new List<JsonConverter>() { dateTimeConverter }
    };

Like I said, it works fine on the simulator, but very wrong in the device. Not like timezone offset wrong, like dates into the year 5000. Any ideas would be greatly appreciated.

Regards, Brandon


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>