更新时间:2023-11-29 19:47:34
我猜你想返回该类作为JSON。
I guess you want to return that class as JSON.
你可以做的仍然是使用的StringContent
的构造函数,但是传递一个JSON序列化的字符串。你可以使用Newtonsoft.Json作为系列化。
What you could do is still use the StringContent
constructor, but pass in a JSON serialized string. You could use Newtonsoft.Json as serialized.
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent(JsonConvert.SerializeObject(yourObject))
});