0

I am trying to create a .json file from a string of coordinates to display. I can get to the point of creating the file but the JSON Is not correct. Code follows

json="10,10;10,5;5,5;5,10"
 List<Coords> eList = new List<Coords>();
                Coords d = new Coords();
                d.type = "Polygon";
                d.coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject(json);


                List<def> deflist = new List<def>();
                def f = new def();
                f.type = "GeometryCollection";
                f.geometries = d;
THE RESULTS ARE

        {
          "type": "GeometryCollection",
          "geometries": {
            "type": "Polygon",
            "coordinates": [
              [
                [
                  10,
                  10
                ],
                [
                  10,
                  5
                ],
                [
                  5,
                  5
                ],
                [
                  5,
                  10
                ]
              ]
            ]
          }
        }

    -- SHOULD LOOK LIKE THIS

    {
      "type": "GeometryCollection",
      "geometries": {
        "type": "Polygon",
        "coordinates": [
          [[10,10],[10,5],[5,5],[5,10]]
        ]
      }
    }

the coordinates are indented and formatted in a way I can't understand. Any suggestions would be greatly appreciated.

The File is being generated to be used with Telerik RadMap Control.

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • That's how Json.NET formats and indents arrays. Since whitespace is purely cosmetic according to the [standard](http://json.org/), it's neither right nor wrong. You could [disable indenting](http://stackoverflow.com/questions/7947005/how-to-turn-on-indentation-when-writing-json-using-json-net) if you don't like it. – dbc Sep 16 '15 at 09:29
  • But if your receiving system is broken and is sensitive to whitespace, see [Newtonsoft inline formatting for subelement while serializing](https://stackoverflow.com/questions/30831895/newtonsoft-inline-formatting-for-subelement-while-serializing) or [How to apply indenting serialization only to some properties?](http://stackoverflow.com/questions/28655996/how-to-apply-indenting-serialization-only-to-some-properties). – dbc Sep 16 '15 at 09:30

0 Answers0