How to convert DateTime object to json

后端 未结 4 1278
忘掉有多难
忘掉有多难 2021-01-01 12:47

How to convert DateTime object to json? It throws Converting object to an encodable object failed., so is this a bug or it\'s just dart

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 13:30

    first: JSON does not support date/time encoding.. this is usually done by convention depending on the other party - usually a string representation (e.g. ISO8601 but Microsoft's ASP.NET uses a custom format).

    second: How to convert an object containing DateTime fields to JSON in Dart?
    (In short: Runtime does not serialise DateTime. You'll need to create a wrapper with custom serialisation logic.)

提交回复
热议问题