![](/img/trans.png)
[英]How can I serialize an object with a Dictionary<string,object> property?
[英]How can I serialize a Dictionary<string, object> to javascript?
这是我的代码:
public class PuntoMappa
{
string Lat;
string Lng;
public PuntoMappa(string Lat, string Lng)
{
this.Lat = Lat;
this.Lng = Lng;
}
}
PuntiCategoriaMappa.Add("1111", new PuntoMappa("1", "2"));
PuntiCategoriaMappa.Add("2222", new PuntoMappa("3", "4"));
PuntiCategoriaMappa.Add("3333", new PuntoMappa("5", "6"));
var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PuntiCategoriaMappa", "PuntiCategoriaMappa = " + jsonSerializer.Serialize(PuntiCategoriaMappa) + ";", true);
但是序列化是:
PuntiCategoriaMappa = {"1111":{},"2222":{},"3333":{}};
好吧,我丢失了PuntoMappa
对象的序列化。
如何正确执行此操作?
您必须公开提供Lat和Lng。
public class PuntoMappa
{
public string Lat { get; private set; }
public string Lng { get; private set; }
public PuntoMappa(string Lat, string Lng)
{
this.Lat = Lat;
this.Lng = Lng;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.