skip to Main Content

I would like som help. Im trying to create a Json object with the outcome below.
Im not able to get my head around how it should be done with all the nesting. Can anyone help me out?

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            12.82114,
            56.6762238
          ],
          [
            12.8211,
            56.67633
          ],
          [
            12.82085,
            56.67668
          ],
          [
            12.82106,
            56.6767
          ],
          [
            12.82135,
            56.67675
          ],
          [
            12.82164,
            56.67683
          ],
          [
            12.82188,
            56.67693
          ]
        ]
      },
      "properties": {
        "stroke": "blue"
      }
    }
  ]
}

2

Answers


  1. Try something like this:

    public class Geometry
    {
        public string type { get; set; }
        public List<List<double>> coordinates { get; set; }
    }
    
    public class Properties
    {
        public string stroke { get; set; }
    }
    
    public class Feature
    {
        public string type { get; set; }
        public Geometry geometry { get; set; }
        public Properties properties { get; set; }
    }
    
    public class FeatureCollection
    {
        public string type { get; set; }
        public List<Feature> features { get; set; }
    }
    
    Login or Signup to reply.
  2. https://json2csharp.com
    Try this tool. Just enter your json object there and it convert make a c# class for you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search