Serialize NodaTime JSON

前端 未结 2 1780
南方客
南方客 2021-02-10 07:40

I am making a prototype project of NodaTime compared to BCL\'s DateTime, but executing this result gives me recursionLimit exceeded error.

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 08:08

    We don't currently have any support for JavaScriptSerializer: I suspect you'll have to use Json.NET for all your JSON serialization. The user guide page on serialization gives a little bit more information, but it does mostly assume you already know about Json.NET.

    The good news is that Json.NET is pretty easy to use - you may well find it's as simple as:

    var settings = new JsonSerializerSettings();
    settings.ConfigureForNodaTime();
    string json = JsonConvert.SerializeObject(model, settings);
    

    (Or use JsonSerializer.)

    As an aside, the way you're using the Noda Time types is a little odd to say the least - it may well be worth asking another question with details of what you're trying to achieve, and we can work out a more idiomatic way of doing it :)

提交回复
热议问题