chobo2
chobo2

Reputation: 85765

How to Create This Json?

Say I have this hardcoded code,

$("#test").gmap3({
  map:{
    options:{
      center:{lat:24.886436490787712,lng:-70.2685546875},
      zoom:3,
      mapTypeId: google.maps.MapTypeId.TERRAIN
    }
  },
  polygon: {
    values: [
      {
        options:{
          strokeColor: "#FF0000",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#FF0000",
          fillOpacity: 0.35,
          paths:[
            [25.774252, -80.190262],
            [18.466465, -66.118292],
            [32.321384, -64.75737],
            [25.774252, -80.190262]
          ]
        }
      },
      {
        options:{
          strokeColor: "#FF0000",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#FF0000",
          fillOpacity: 0.35,
          paths:[
            [37.33522435930639,-97.7783203125],
            [37.33522435930639,-85.8251953125],
            [29.420460341013133,-86.3525390625],
            [23.120153621695614,-97.0751953125]
          ]
        }
      },
      {
        options:{
          strokeColor: "#FF0000",
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: "#FF0000",
          fillOpacity: 0.35,
          paths:[
            [21.002471054356725,-52.4267578125],
            [28.34306490482549,-47.1533203125],
            [17.35063837604883,-35.7275390625],
            [11.049038346537106,-49.0869140625],
            [8.276727101164045,-61.2158203125]
          ]
        }
      },
    ],
    onces:{
      click: function(polygon){
        polygon.setOptions({
            fillColor: "#FFAF9F",
            strokeColor: "#FF512F"
        });
      }
    }
  }
});

I am wondering how can I create the "Values" section from C# code.

I have this so far.

public class Options
{
    public string strokeColor { get; set; }
    public string strokeWeight { get; set; }
    public string fillColor { get; set; }
    public string fillOpacity { get; set; }
    public string strokeOpacity { get; set; }
}

This I guess would be a collection(or array) but not sure about paths. I am what that would be. It has to be some sort of array within array but it can't have any property names.

Upvotes: 0

Views: 53

Answers (1)

Kenneth
Kenneth

Reputation: 28737

This is probably what you want:

public class Options
{
    public string strokeColor { get; set; }
    public double strokeOpacity { get; set; }
    public int strokeWeight { get; set; }
    public string fillColor { get; set; }
    public double fillOpacity { get; set; }
    public List<List<double>> paths { get; set; }
}

public class RootObject
{
    public Options options { get; set; }
}

By the way: I created these classes by copy pasting the JSON into this little tool: http://json2csharp.com/

Obviously, you then need to deserialize this into JSON, but I suppose you know how to do that.

Upvotes: 6

Related Questions