本文整理汇总了C#中Nancy.Response.ContentsFromString方法的典型用法代码示例。如果您正苦于以下问题:C# Response.ContentsFromString方法的具体用法?C# Response.ContentsFromString怎么用?C# Response.ContentsFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Response
的用法示例。
在下文中一共展示了Response.ContentsFromString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSchemas
private Response GetSchemas()
{
var res = new Response();
var schemas = new SchemaGenerator(this.typeMapper).Generate().ToJson();
res.ContentsFromString(schemas);
res.ContentType = "text/plain; charset=utf-8";
return res;
}
示例2: CreatePrettifiedHtmlJsonResponse
public static void CreatePrettifiedHtmlJsonResponse(Response res, string htmlLinks, string json, string baseUri)
{
var htmlPageTemplate =
@"<!DOCTYPE HTML>
<head>
<meta charset='utf-8'>
<style type=""text/css"">
ul
{{
list-style-type: none;
padding: 0px;
margin: 0px;
}}
.search
{{
width: 450px;
}}
ul li
{{
padding-left: 14px;
display: inline;
}} </style>
</head>
<html>
<div><ul>{1}</ul></div>
<div>
<form action=""{2}"" method=""get"">
<div>Query <input type=""text"" class=""search"" name=""$filter"" /></div>
<div>Expand <input type=""text"" class=""search"" name=""$expand"" /></div>
<input type=""submit"" value=""Submit"" />
</form>
</div>
<div>
<pre class=""prettyprint"">
{0}
</pre>
</div>
</body>
</html>";
var sb = new StringBuilder();
var jsonIndex = 0;
while (jsonIndex < json.Length)
{
var linkStart = json.IndexOf("\"http://", jsonIndex, StringComparison.Ordinal);
if (linkStart == -1)
linkStart = json.IndexOf("\"https://", jsonIndex, StringComparison.Ordinal);
if (linkStart != -1)
{
linkStart++; // Skip the quote (")
sb.Append(HttpUtility.HtmlEncode(json.Substring(jsonIndex, linkStart - jsonIndex)));
var linkEnd = json.IndexOf('"', linkStart);
linkEnd = linkEnd != -1 ? linkEnd : json.Length;
var link = json.Substring(linkStart, linkEnd - linkStart);
sb.AppendFormat("<a href=\"{0}\">{1}</a>", link, HttpUtility.HtmlEncode(link));
jsonIndex = linkEnd;
}
else
{
sb.Append(HttpUtility.HtmlEncode(json.Substring(jsonIndex)));
jsonIndex = json.Length;
}
}
var prettifiedJsonHtml = string.Format(htmlPageTemplate, sb, htmlLinks, baseUri);
res.ContentsFromString(prettifiedJsonHtml);
res.ContentType = "text/html; charset=utf-8";
}