C#中的JSON不是针对正确呈现 [英] c# to json not rendering properly in view
本文介绍了C#中的JSON不是针对正确呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜林试图发送一个字符串,看起来像JSON视图
Hi Im trying to send a string to a view that looks like json.
林发送的地点清单:
class Place
{
public string title { get; set; }
public string description { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
}
List<Place> placeList = new List<Place>();
//add places to PlaceList
//Then i do this
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(placeList);
ViewBag.Places = sJSON;
在认为它像这虽然渲染输出:
In the view its rendering output like this though:
[{"title":"sdf sdfsd sdf sd f","description":"sdf sdf sd fsd sd sdf sdf dssd sdf sd s","latitude":53.740259851464685,"longitude":-2.4602634343627927},
我如何得到它呈现为在视图中正常的JSON?减去&放大器; QUOT;
等?
How do i get it to render as normal json in the view? minus "
etc?
推荐答案
在您的评论下面你说你的看法是使用 @ ViewBag.Places
In your comment below you say your view is using @ViewBag.Places
您使用剃刀?如果是这样的 @
语法做同样的事情为<%:
- 它编码的内容
Are you using Razor? If so the @
syntax does the same thing as <%:
- it encodes the content.
使用的 IHtmlString
接口,以避免它,所以无论是:
Use the IHtmlString
interface to avoid it, so either:
ViewBag.Places = new HtmlString(sJSON);
或
@HtmlString(ViewBag.Places)
这篇关于C#中的JSON不是针对正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文