Results 1 to 29 of 29

Thread: [RESOLVED] JsonConvert.DeserializeObject to object

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Resolved [RESOLVED] JsonConvert.DeserializeObject to object

    Hi.
    Is it possible to deserialize to an unknown object with:

    Code:
       Dim o As New Object
            o = JsonConvert.DeserializeObject("somejson")
    ?
    If I do that I get properties that include Json string.
    I was wondering if it is possible to create an object that has properties a classes of the Json. Or do I need to declare the complete structure of the Json response to classes and the use an instance of the main created class to deserialize?

    Thanks.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: JsonConvert.DeserializeObject to object

    VB .NET is strongly-typed and statically-typed. That means objects have to have a class define their properties and methods at compile time.

    You could try using ExpandoObjectConverter. That uses a special API called the "Dynamic Language Runtime" that uses the ExpandoObject type. The shortest way to describe what it does is "it makes a Dictionary act like an Object, sort of." When you do this, you end up having to do a lot of extra casts, because generally the property types are Object.

    You could also try deserializing to a Dictionary(Of String, Object). That's more or less what a "dynamic object" is. It has the same kind of casting behavior that ExpandoObject has. You get the best experience if you deseriailze to a known object. When you're doing a job that doesn't let you deserialize to objects you know up-front, it's much easier to use a more dynamic language like JavaScript, Ruby, or Python.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Hi.
    OK what I'm doing is facing the fact that I need to deserialize to classes.
    So I'm writing the classes down from JSon. The problem is that the example value is something like that:
    Code:
     "BalanceTypeID": "string",
            "Name": "string",
            "Message": "string",
            "PointsRemaining": 0,
            "LifetimePointsBalanceDisplay": 0,
            "IsDefault": true,
    You can happily see that the jsonutils will translate this to string and integer. Huuungkkk! Wrong. This was actually specified as a number in the documentation so i guess double. Also the dates are no dates, they are string!
    So anyhow I need to do a lot here so I would either let this Jsonize to the response or deserialize all the classes. Hmmm.

    Anyway the way i deserialize is like so:
    dim myclassDes = JsonConvert.DeserializeObject(Of myclass)(JsonData)
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: JsonConvert.DeserializeObject to object

    It can only deserialize based on what it has.,.. if I had the above, I'd make the same assumptions... string, integer... how else could I know any different? That's why it's up to the destination class to define what it should look like: Ooooh, ok, the PointsRemaining is a double... ok, convert 0 to 0.0 .... and so on.
    As for dates, read the documentation, they maybe represented as a string in the JSON, but you may find out they are in an ISO format... I'm starting to work with some endpoints that generate JSON data that uses a specific ISO date format that is time zone agnostic. This allows anyone from anywhere to pull any information with locally accurate dates. So in the documentation, our dates are defined as "string".

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Actually the date returns like this: "/Date(4081363200000)/" . Haven't seen that again....Or maybe I have a long time ago...
    Is this supposed to be and integer interval representation?Is this what you are talking about?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: JsonConvert.DeserializeObject to object

    Woah.... no... that's not what I envisioned.... O.O
    Ours is in an actual ISO format of YYYY-MM-DD HH:mm:ss-ZZ (ZZ represents the timezone offset from GMT) or something along those lines... that's what I expected. What you're showing looks closer to how times are stored in a database - the number of ticks since a given time. Judging by the number of zeros on the end there, I'd say it's a date only, no time component. The question is: What's the starting interval? Interesting. If you know what it should be, you might be able to work back into it. Or, just simply take the value and cast it as a date and see what it converts it to. See if it gets it right. Have to admit, I think that's a bit whacked on their part to return data ambiguous as that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Well.
    I get this : #5/3/0130 12:00:00 AM#
    This can not be correct.

    What are they thinking? I have to remove the date and "/" things and then do this:
    Code:
       Dim ts As TimeSpan = TimeSpan.FromMilliseconds(4081363200000)
                Dim dtm As New DateTime
                dtm = dtm + ts
    If i do this:
    TimeSpan.FromTicks(4081363200000)
    I get this:
    #1/5/0001 05:22:16 PM#

    What the?!
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Come to think of it.
    I think you need a reference point in time to get the timespan.
    So I have no idea what idiotic construction is this.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: JsonConvert.DeserializeObject to object

    So I checked on Javascript dates, which are based on the number of milliseconds since Jan 1, 1970.... and I get 5/02/2099....
    Code:
            Dim ts As TimeSpan = TimeSpan.FromMilliseconds(4081363200000)
            Dim dtm As New DateTime(1970, 1, 1)
            dtm = dtm + ts
    
            MessageBox.Show(dtm.ToShortDateString())
    Still doesn't seem right... but seems more right than 5/3/0130...

    but./... if you change it to offset from 1/1/1900 ... it comes out to a reasonable 5/2/2029....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: JsonConvert.DeserializeObject to object

    Quote Originally Posted by sapator View Post
    Come to think of it.
    I think you need a reference point in time to get the timespan.
    So I have no idea what idiotic construction is this.
    5 months, 3 days, 130 years.... :P but yeah, you need a reference point to start with when adding a timespan to a date.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    I have to ask them.
    Idiots, I'm surrounded by idiots. Oh duh lets build a date interval. Duhh let's make it a double. Do we need to specify a point in time reference.........Naaahhhh!!
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  12. #12

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Hmmm. I see a create member web call. I should try if this works instead of asking them because I've very mad with all my time wasted these days with their bs service and their bs support and bs and $!@##$@ @#$ and aaaaaaaaa!!!!.
    Fffff OK got it out of my system "/Date(4081363200000)/" and bs and stuff. "/Date(4081363200000)/". I mean "/Date(4081363200000)/"
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  13. #13

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Right.
    Now I have a value DateOfBirth "-62135596800000"
    This will hit an exception with 1/1/1900 and will produce year 0021 with any other close calls.
    Unfortunately I have to ask them.

    Edit. I asked. From other tests, seems like what you suggested for JavaScript 1/1/1970 date looks reasonable.
    I'm saying this because "-62135596800000" will actually go to a 1/1/0001 so it looks like the beginning of counting years.
    Let alone that is both starting number and Christianized
    Last edited by sapator; Feb 13th, 2018 at 10:36 AM.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  14. #14
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: JsonConvert.DeserializeObject to object

    You are going to have to ask them what their Date format is.

    JSON only represents types that are native to JavaScript and easily representable in text. Dates are extremely difficult to represent in text, and people have various preferences for them in JavaScript, so it doesn't have a standard Date/Time type. That means part of using an API is finding where they document their date/time format and writing a teeny bit of code to parse it properly.

    I'm as stumped as you are. The time is clearly some duration past an epoch, but you need to know the unit of the duration and the epoch to make any sense of it. You're going to have to get that information from the API creator, or reverse engineer it from some data where you know what the date should parse to.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  15. #15
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: JsonConvert.DeserializeObject to object

    What the what? Who's writing that api? A bunch of monkeys? I bet there's a bunch of guys rolling some D20 dice coming up with random date values....

    I feel for ya man.... I really do...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    So I've send an email yesterday to their support site.
    I'm currently skipping this and doing other stuff until the decide to let me know. Maybe, if I have some time today, I'll try out the create user web call and try to pinpoint the date.And now I've started to giggle thinking that in the date field, they might require to use the same customization to pass the date. Lol!
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  17. #17

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: JsonConvert.DeserializeObject to object

    Vzzzzzzz!
    OK so I created the member. I used these dates on the service "2000-02-14T07:59:44.006Z" , "2000-02-14" . I got a return of "/Date(950486400000)/" .
    Now the fun part. Validating the member and getting the date with "1/1/1970" is the member created date, without the time, so it's "2000-02-14 12:00:00AM" .
    So it appears that the service has a point in time "1/1/1970" for output date, moreover the input dates can be of various formats.
    Now, problem solved but I', thinking that since they have not replied back for such a simple issue, they understand that they have made a bs in their service and they are probably trying to fix it. Will see but anyhow I will mark this as resolved since the date comes out correctly with this point in time and it is not something I am doing wrong.
    Last edited by sapator; Feb 14th, 2018 at 07:25 AM. Reason: qui vitahm fibi ducendam cicgit, naturæ,propenfioni, fiue ingenio fuo acgomnmodam
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  18. #18
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Just for fun... can you stuff in a 1/1/1970 as a date and see what comes back? If 1/1/70 is the epoch, then it should come back as 0, right? Or is the date you're getting back something that you're not sending in the first place?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Yes.
    I'm sending "1970-01-01"
    and getting back "/Date(0)/"

    I asked them why they are accepting a valid date as an input and giving back a number as an output. Still waiting for an answer.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  20. #20
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Hi,

    I found this a while back
    https://blogs.msdn.microsoft.com/bcl...e-faq-entries/

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  21. #21

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Well this says that storing date in int64 is bad.
    So you are bashing our partner company and imply that they have not created a valid web service. Another comment like that and it's spasmic cat time!!
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  22. #22
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Quote Originally Posted by sapator View Post
    Well this says that storing date in int64 is bad.
    So you are bashing our partner company and imply that they have not created a valid web service. Another comment like that and it's spasmic cat time!!
    I wansN't implying, but they sure are sending some strange stuff
    please not spasmic cat's again;-)
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  23. #23
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Quote Originally Posted by sapator View Post
    Well this says that storing date in int64 is bad.
    So you are bashing our partner company and imply that they have not created a valid web service. Another comment like that and it's spasmic cat time!!
    OK, I think you misread both the reason for the article being posted and the thing the article meant to say.

    DateTime is a very, very, VERY complicated type to deal with. I could write an entire chapter in a book about all of the things you have to worry about with it. Part of the reason it is so complex is because by itself, it does not have all of the information you really need to pinpoint a time.

    Think about the time "2:15 AM".

    When we think about that simply, we know it will happen tomorrow, it will happen yesterday, and that every day of the year will have a 2:15 AM. But we also know that, in any given day, "2:15 AM" happens 24 times across each time zone. When it's "2:15 AM" in my time zone, it's "3:15 AM" in another and "1:15 AM" in yet another. So here's our first problem: due to time zones, the same moment in time has many different representations, and they are all correct.

    Now think about some other rules. Not all time zones are 1 hour apart. Some places in the world are offset 30 minutes from other time zones. Some are offset 15 minutes! The reasons are generally political, but now our rule is more complex: any given moment in time can have more than 24 "correct" representations.

    Also: daylight savings time can affect time in strange ways. In time zones that observe it, there is one hour of the year that does not exist because the DST shift consumes it. For example, clocks may be instructed to move from 02:59:59 to 04:00:00 and completely skip all of the times between 03:00:00 and 03:59:59. In these places, there is also an hour that happens twice. For example, clocks may be instructed to move from 02:59:59 to 02:00:00 and repeat the hour between 02:00:00 and 03:00:00 twice.

    So a DateTime is usually "a number that represents a duration past some reference point, and information about how to interpret that as a date and time". The "information" is generally "a time zone". But therein lies the problem.

    The only time zone DateTime can reliably represent is UTC, if its DateTimeKind is specified as DateTimeKind.Utc. But by default, it is DateTimeKind.Local, which means "use the time zone of this machine". Here's where things get messy.

    If you convert the DateTime to Binary by storing Ticks, like the article mentions, then you are NOT storing the time zone. So if you store "today at 10 AM" in Chicago, you'll get some number. If you load that number while still in Chicago, you'll still get "today at 10 AM". But. Let's say you fly to Arizona. It's a different time zone, and some Arizona time zones do NOT represent Daylight Savings. Now if you load that DateTime, what you get can be wrong in several ways:
    • You might get "today at 9 AM", because Daylight Savings has shifted the hour.
    • You might get "today at 11 AM", because Daylight Savings has shifted the hour.
    • You might get "today at 10 AM", which could be wrong because you wanted "10 AM in Chicago's time zone".

    You can sidestep these issues if and only if you commit to only ever serializing UTC times. UTC never uses daylight savings. This can still run afoul of the last case, though. You start with "10 AM in Chicago" and convert to some time in UTC. Now when you load that UTC time, you can always convert to some other time, but you don't now what the original intended time zone was.

    So it is usually best to store more than just "the number" related to a DateTime. The least you want to add to that is, "What is the UTC offset for this moment?" to help you understand the time zone rules at play.

    But in general, if you want to be most accurate about storing dates and times, you need to store:
    • The epoch you are using.
    • The offset from the epoch.
    • The units used by the offset.
    • Information about all of the time processing rules used for the moment. (A gps coordinate or a time zone.)

    We can cheat some of those rules: generally we use standards to determine the epoch and units of the offset. But if you have no time zone information at all, it is very easy to be in situations where you don't load the appropriate time if all you have is an offset. That's why the article cautioned against using int64 for "local" times.

    So let's say you serialize "number of seconds since January 1, 1970 in UTC". That means you have a known epoch, an offset, a known unit, and a time zone that helps you know the date and time of the offset. That's all the information you need!

    But let's say you serialize "number of seconds since January 1, 1970 in CST since I'm in Chicago". If you load that time while in a different time zone with different Daylight Savings settings, you might be an hour or more inaccurate, or the time might not even be valid!

    That's what the article means.

    Now, that doesn't mean what your API is doing is bad. 99% of APIs tend to take one of these three approaches:
    • Send the time as an ISO string with offset, such as "13/02/2018T14:25:15+05:00". That's day/month/year with hours/minutes/seconds and "a time zone 5 hours ahead of UTC". Note this isn't quite enough to definitively determine Daylight Savings rules.
    • Send the time as a number with known offset and units, agreeing that all timestamps represent UTC.
    • Send the time as a number with known offset and units, agreeing that all timestamps represent a documented time zone.

    It's the other 1% that make you scratch your head. If you don't know offset, unit, and time zone, things can be tough.

    For example, one API I interact with has to track moving objects. Times are stored in the object's local time zone. The object can, conceivably, cross multiple time zones between entries. So if I want to measure the time between two entries accurately, I actually have to use the GPS positions of each entry to look up which time zone is being used, because a change from "09:15:45" to "10:16:45" might be "1 hour and 1 minute" or "1 minute" depending on where the object was located at either time!

    So the article is pointing out that you have to think [b]very hard[/i] about what your DateTimes represent before you store "just a number".
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  24. #24
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Quote Originally Posted by Sitten Spynne View Post

    But in general, if you want to be most accurate about storing dates and times, you need to store:
    • The epoch you are using.
    • The offset from the epoch.
    • The units used by the offset.
    • Information about all of the time processing rules used for the moment. (A gps coordinate or a time zone.)

    We can cheat some of those rules: generally we use standards to determine the epoch and units of the offset. But if you have no time zone information at all, it is very easy to be in situations where you don't load the appropriate time if all you have is an offset. That's why the article cautioned against using int64 for "local" times.

    So let's say you serialize "number of seconds since January 1, 1970 in UTC". That means you have a known epoch, an offset, a known unit, and a time zone that helps you know the date and time of the offset. That's all the information you need!

    But let's say you serialize "number of seconds since January 1, 1970 in CST since I'm in Chicago". If you load that time while in a different time zone with different Daylight Savings settings, you might be an hour or more inaccurate, or the time might not even be valid!
    I didn't read the article, where I struggled with the problem is with the api authors and what I appear as a lack of documentation... simply having a field and calling it a "date" but returning a numerical value with nothing else leaves a lot to be desired. It does become apparent that it is based on an epoch, but then WHAT epoch... again, the lack of documentation leads to more frustration... That's where most of the issue in this thread have come from. Not from a lack of understanding anything... more of a frustration at a lack of communication.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  25. #25
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    But, yes you're right... you have to save the date with some kind of context. But again, that was part of the problem... sap was getting something back, we were reasonable sure it a milliseconds since... but the missing context was the epoch from the web api. Problem wasn't with sap's code or data... it was the data from the webapi. It didn't have a documented context.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  26. #26

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    It's as techgnome says. Plus i did not read all this through, just the part that striked my mind.

    Unfortunately in Greece we use the dd/mm/yyyy spec so I should imaging, after all those years, I have grasped the general idea of date conversion, since almost everything i use date with, must be translated to another date format. Granted I haven't used decimal like this for a format (with /date/number full included) but ,as I've said, it got me thinking immediately (see post #5), this goes to show that date conversion experience from Greek date was useful ( ).

    I will update if I ever get a response from the developers.
    Last edited by sapator; Feb 15th, 2018 at 10:34 AM.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  27. #27

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    OK they replied.
    So the answer was to look at this site https://www.freeformatter.com/epoch-...converter.html
    So duh, yes the site specifies 1/1/1970 but it's like they are not admitting that the did not have absolute no documentation and they just go like "Oh you should have known that it was 1/1/1970", look this site , it's elementary! ". Apart from that, their documentation specified date as "string" because they not supply just number but "/Date(4081363200000)/" .There is nothing like that in the article they have send me. It's pure numbering not string. So I think this is not a standard documentation Javascript default but their own custom materialization. Anyway I didn't want to deal with them anymore so I just went along and send a simple "Thanks, you could have told me 1/1/1970 was the epoch"

    Anyway this is the first time a have to deal with this kind of date manipulation. I have created a function to translate the double to a valid date I can use.

    P.S. Epoch comes from the Greek word "Epochi - Εποχή" that means season (winter,spring etc)

    Edit. It could also mean period(Greece "Περίοδος") in time but it mostly used as "Εποχή". Period would be more acceptable in a Greek dialog than epoch but I guess they made a booboo initially and kept it that way.
    Last edited by sapator; Feb 20th, 2018 at 07:19 AM.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  28. #28
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    One of the things you learn in programming is that in general, we pick 1/1/1970 as Epoch. I'm sure there's some reason why that specific date, but it's the most common epoch used for all date types.

    One of the things you learn in programming is we really value ancestral knowledge like that, and don't tend to document it because we assume "everybody knows that".

    You quickly learn there are two types of developer, one is more prevalent, and that kind of developer's the one no one likes.

    That kind of developer likes to roll their eyes and make people who don't have the ancestral knowledge feel bad. These people have fallen prey to a nerd tendency and take pride in proving they have more knowledge than others. It's a healthy human trait, but can be misapplied. Normal people get excited when they can outperform an expert. These people get just as excited if they outperform a newbie. When they aren't busy haunting programmer forums for that rush, you can find them in kindergarten classes insulting children who can't read yet.

    The best you can do is strive to not be that guy. When you find yourself tempted to "let me google that for you" or otherwise imply "this question's so dumb it's not worth my time to answer it", try to put your money where your mouth is and remember it's better to not answer a question than to make a person feel bad for asking.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  29. #29

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: [RESOLVED] JsonConvert.DeserializeObject to object

    Nice post.
    Anyhow I did not feel bad for me but more for their support and it would have taken a whole lot more to make me feel bad, if ever (I'm a little "thick skinned" at this kind of domain, fortunately or unfortunately).
    The issue we are having is that sometimes we need fast accurate answers and we do not get that. Granted this is a project that it's not no1 on our agenda but we had issues with other questions that needed immediate answer. From my understanding they are just pushing the non emergency answers back and as they have customers from all over the world to manipulate (at a time I was given a Chinese manual for help by them, probably mixed the customers by mistake, now I know how you guys feel when you try to understand Greek :P ) they give priority to more important and emergency issues. If I was given a go from out It Manager to push this matter as highly important, they should probably have answered immediately and more accurately but as you can understand, we do not want to flag anything as critical as we might not get help on a really critical issue if everything is flagged the same way.
    Peculiarly, I asked them for a database removal of live data (as we would need to delete and upgrade a current one with new data) and they answered the next day. Probably if you bump to an agent that is assigned a question that is to his / her field then you are in luck and you get an answer....Well or maybe that was a "take that and don't bother us for a while" bonus.
    Damn I have to get to bed...
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width