c# json html转义字符,JSON序列化输出具有C#转义格式

我正在尝试从客户端将更新的对象POST到REST服务器API.我正在使用RestSharp,我正在将我的对象的

JSON表示添加到我的请求正文中.但是,我的序列化对象的字符串表示格式错误.服务器拒绝它.

我的请求看起来像这样(我用Fiddler来获取它)

PUT https://myapp.net/api/PriceListItems/151276 HTTP/1.1

Accept: application/json,application/xml,text/json,text/x-json,text/javascript,text/xml

User-Agent: RestSharp/104.4.0.0

Content-Type: application/json

Host: myapp.net

Content-Length: 75

Accept-Encoding: gzip,deflate

"{\"Id\":151276,\"AgendaId\":0,\"CurrencyId\":1,\"Code\":\"\",\"Price\":7.0}"

我曾尝试使用Json.NET,RestSharp的内部Json序列化程序以及System.Web.Script.Serialization中的JavaScriptSerializer来序列化我的对象.全部以这种格式返回一个字符串.我知道这种格式化的原因是因为C#转义双引号所以它可以在里面正确显示它,但我不明白我应该如何将它传递给我的请求没有这种转义格式.我知道服务器接受正确形成的JSON这一事实.

我尝试序列化的对象看起来像这样

public class PriceListItem

{

public static PriceListItem CreatePriceListItem(int id,int agendaId,int currencyId,string code,string unit,decimal price)

{

var priceListItem = new PriceListItem

{

Id = id,AgendaId = agendaId,CurrencyId = currencyId,Code = code,Price = price

};

return priceListItem;

}

public int Id { get; set; }

public int AgendaId { get; set; }

public int CurrencyId { get; set; }

public string Code { get; set; }

public decimal Price { get; set; }

编辑:

将我的解决方案从此处移至答案.