【发布时间】:2009-06-29 03:29:41
【问题描述】:
我在 .ashx 响应中通过 JSON 发回一堆图像标签。
我不确定如何格式化,以便字符串返回真实标签。我尝试了 HtmlEncode 并修复了它,但后来我得到了这个愚蠢的 \u003c 废话:
["\u003cimg src=\"http://www.sss.com/image/65.jpg\" alt=\"\"\u003e\u003c/li\u003e","\u003cimg src=\"http://www.xxx.com/image/61.jpg\" alt=\"\" \u003e\u003c/li\u003e"]
\u003c 到底是什么?
这是我创建 JSON 以响应我的 .ashx 的代码:
private void GetProductsJSON(HttpContext 上下文) { context.Response.ContentType = "文本/纯文本"; int i = 1;
...做更多的事情
foreach(Product p in products)
{
string imageTag = string.Format(@"<img src=""{0}"" alt=""""></li>", WebUtil.ImageUrl(p.Image, false));
images.Add(imageTag);
i++;
}
string jsonString = images.ToJSON();
context.Response.Write(HttpUtility.HtmlEncode(jsonString));
}
toJSON 只是使用此处概述的辅助方法:
【问题讨论】:
标签: asp.net