How to convert an object containing DateTime fields to JSON in Dart? -


i try convert object json.

  var obj = { "dt": new datetime.now() };   var s = stringify(obj); 

the runtime throws exception: "calling tojson method on object failed."

that's expected since datetime class doesn't have tojson method. should in case?

javascript's json.stringify function has optional argument replacer allows me provide own way of serialization of object if object has no tojson method. there similar facility in dart or maybe can extend somehow datetime class own tojson method?

zdeslav vojkovic's answer outdated now.

the json.encode() method in dart:convert has optional toencodable method invoked objects not natively serializable json. it's user provide closure returns appropriate serialization of datetime.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -