C#学习教程:c#makesjsonnotrenderingcorrectlyinview我发送一个列表:classPlace{publicstringtitle{get;放;}公共字符串描述{get;放;}publicdoublelatitude{get;放;}公共双经度{get;放;}}列表placeList=newList();//将位置添加到PlaceList//然后我这样做System.Web.Script.Serialization.JavaScriptSerializeroSerializer=newSystem.Web.Script.Serialization.JavaScriptSerializer();字符串sJSON=oSerializer.Serialize(placeList);ViewBag.Places=sJSON;它在视图中的渲染输出如下:[{"title":"sdfsdfsdsdfsdf","description":"sdfsdfsdfsdsdsdfsdfdssdsdfsds","latitude":53.740259851464685,"longitude"":-2.4602634343627927},如何让它在视图中呈现为纯json?减去"等?在下面的评论中,您说您的视图正在使用@ViewBag.Places您是否正在使用Razor?如果是这样,@语法的作用与-它对内容进行编码。使用IHtmlString接口来避免它,所以:ViewBag.Places=newHtmlString(sJSON);或@HtmlString(ViewBag.Places)@Html.Raw(ViewBag.Places)也有效你试过了吗?以上就是C#学习教程:c#阻止json在视图中正确显示所有共享内容。如果对大家有用,需要详细了解C#学习教程,希望大家多多关注---stringsJSON=HttpServerUtility.HmltDecode(oSerializer.Serialize(placeList));本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
