0

This is my code :

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); 

but the serialization is :

PuntiCategoriaMappa = {"1111":{},"2222":{},"3333":{}};

Well, I lost the serialization of PuntoMappa objects.

How can I correctly do this?

1 Answer 1

5

You have to make the Lat and Lng publicly accessible.

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;
    }
}  
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.