Ciao Sto cercando di inviare una stringa a una vista che sembra JSON.C# to json non viene visualizzato correttamente nella vista
Im invio di un elenco di luoghi:
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;
Nella vista la sua uscita rendendo in questo modo però:
[{"title":"sdf sdfsd sdf sd f","description":"sdf sdf sd fsd sd sdf sdf dssd sdf sd s","latitude":53.740259851464685,"longitude":-2.4602634343627927},
Come faccio a farlo rendere come normale JSON nella vista? meno "
ecc.?
anche io penso che è strano che il ritorno oSerializer.Serialize stringa codificata in html. Come sei sicuro che il rendering nella tua vista non abbia pre-trattamento? –
Ho provato: HttpUtility.HtmlDecode (oSerializer.Serialize (placeList)); - stesso risultato – raklos
nella mia vista ho: "posti": @ ViewBag.Places – raklos