How to serialize a dynamic object to a JSON string in dotnet core?

后端 未结 2 790
广开言路
广开言路 2021-01-20 17:42

I am passing a JSON payload to an API Controller, and one of the fields is dynamic because the field needs to be passed again as a JSON string to another API. The dotnet co

2条回答
  •  长发绾君心
    2021-01-20 17:58

    I had the same problem and I fixed it this way

    using System.Text.Json;
    
    string serializedObject = JsonSerializer.Serialize(x.Action); //Instead of use JsonConvert.SerializeObject(x.Action);
    

    Instead of Newtonsoft.Json you have to use System.Text.Json.

提交回复
热议问题