【发布时间】:2018-06-08 16:59:13
【问题描述】:
使用 C# 将 HTML 字符串作为 JSON 输出。
我想用 ' 替换 HTML 包装器 之间的每个实例,同时转换为 JSON。同时,如果它有带有 " 引号的文本,那么它不应该被替换为 ' 引号。例如。 "since the 1500s"
代码 - 将所有 " 替换为 ' 引号
public string Content
{
get
{
return _content;
}
set
{
if (value != null)
{
this._content = this._content.Replace("\"", "'");
}
}
}
我正在从我的视图中获取这种形式的字符串。
E.g. model.Content = "<p> Lorem Ipsum is simply dummy text of the printing <span id= "#" ids= "#" display= "inline" ></ span > and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever "since the 1500s".<br></p>";
我正在使用 JsonConvert.SerializeObject
string output = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
预期字符串 - HTML 标记中的所有双引号应转换为单引号,但文本引号应与使用 C# 时一样
"content": "<p><b>Lorem Ipsum</b> is simply dummy <i>text </i>of the printing <span id='#' ids='#' display='inline'></span> and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever \"since the 1500s\".</p>",
【问题讨论】:
-
请您提供更多信息。例如,为什么双引号应该变成单引号?您如何将其转换为 JSON 等?
-
是c#返回这个输出的方法吗?请提供更多信息
-
您使用的是 JSON.NET 还是 JavaScriptSerializer 或任何其他 Serializer?
-
@Jack 用代码更新你的问题会很有用,否则那只是一团糟。 ps 也尝试一下格式化它
-
更新问题