嗨我試圖發送一個字符串到一個看起來像json的視圖。c#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;
在鑑於其渲染輸出這樣雖然:
[{"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的看法?減去"
等?
我也覺得很奇怪,oSerializer.Serialize回報html編碼的字符串。您確定您視圖中的渲染沒有任何預處理? – 2011-01-05 15:02:49
我試過了:HttpUtility.HtmlDecode(oSerializer.Serialize(placeList)); - 相同的結果 – raklos 2011-01-05 15:04:32
在我看來,我有:「地方」:@ ViewBag.Places – raklos 2011-01-05 15:05:55