GithubHelp home page GithubHelp logo

Comments (2)

mweimer avatar mweimer commented on September 17, 2024

Hi,

So I reviewed this some more and did some testing, and the code is actually behaving correctly per the JSON spec. When you serialize a DateTime into a JSON string, it must be in a string enclosed in escaped double-quotes. So, your example became ""2015-04-22T22:18:54.000Z"". This is a correctly formatted DateTime in JSON. The datetime conversion utility method is expecting a normal date-time string, not formatted in JSON. So it needs just: "2015-04-22T22:18:54.000Z". In order to achieve this in your code snippet you need to deserialize the serialized object so you need to add a line of code.

 DateTime nowTime = DateTime.Now;
 JsonSerializer dataSerializer = new JsonSerializer(DateTimeFormat.ISO8601);
 string jsonString = dataSerializer.Serialize(nowTime);
 string deserializedJsonString = (string)dataSerializer.Deserialize(jsonString);
 DateTime convertTime = DateTimeExtensions.FromIso8601(deserializedJsonString); 
 Debug.Print("Converted: " + jsonString);

from json.netmf.

poundy avatar poundy commented on September 17, 2024

Awesome - the example deserializes into the hashtable, which is the difference that my scenario didn't, and the relevance of that didn't strike me. The interesting thing is that VS's JSON visualizer handled it fine when looking at the local variable, so it must cater for stripping the quotes.

I am hitting another issue but think this one will be harder to figure out - still working through it and will report back separately if I think there's something you can do. I am sending JSON objects over a 2.4ghz wireless link and when I get transmission issues, I always end up with data inconsistencies. which can lead to repeated keys that probably don't get hashtabled too well :)

from json.netmf.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.