2011-01-05 22 views
10

こんにちは、私はjsonのように見える文字列を送信しようとしています。c#to 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; 

ビューでは、このかかわらようにそのレンダリング出力::場所のリストを送信する

イム

[{&quot;title&quot;:&quot;sdf sdfsd sdf sd f&quot;,&quot;description&quot;:&quot;sdf sdf sd fsd sd sdf sdf dssd sdf sd s&quot;,&quot;latitude&quot;:53.740259851464685,&quot;longitude&quot;:-2.4602634343627927}, 

は、どのように私はそれがビューで通常のJSONとしてレンダリングするのですか?マイナス&quot;など?

答えて

20

あなたのビューでは、カミソリを使用してい@ViewBag.Places

を使用していると言いますか?その場合、@の構文は<%:と同じことを行います。コンテンツをエンコードします。

それを避けるためにIHtmlStringインターフェイスを使用するので、次のいずれか

ViewBag.Places = new HtmlString(sJSON); 

それとも

@HtmlString(ViewBag.Places) 
1

お試ししましたか?もし下のコメントで

string sJSON = HttpServerUtility.HmltDecode(oSerializer.Serialize(placeList)); 
+0

の作品htmlエンコードされた文字列。ビュー内のレンダリングに前処理がないことは確かですか? –

+0

私は試しました:HttpUtility.HtmlDecode(oSerializer.Serialize(placeList)); - 同じ結果 – raklos

+0

私のビュー私は持っている: "場所":@ ViewBag.Places – raklos

5
@Html.Raw(ViewBag.Places) 

また、私はそれは奇妙なことoSerializer.Serializeリターンだと思いも

関連する問題