Deserialize Json Object - DateTime

前端 未结 5 2027
说谎
说谎 2020-12-10 18:37

My web-api returns an User Object. In that object there is a DateTime property. When i\'am reading it in my Application i get an error because the

5条回答
  •  暖寄归人
    2020-12-10 18:54

    To get around this, probably the easiest way is to set the value type on your DataContract type to 'string'. Then, if you need to work with .NET datetimes, you will need to do a DateTime.Parse on your string value. This will eliminate your deserialization problem. It's likely that the original class that was serialized used a string value to begin with, since it is missing the required formatting for dates.

    Note that when you do a DateTime.Parse, if the time zone information is present, it will convert it to the local time of your computer (this is stupid, I know). Just FYI.

提交回复
热议问题