r/visualbasic • • Dec 11 '18

JSON in VB .NET

I am stuck. Can anyone help me?

Problem is this:

I can't get this JSON to parse with newton soft JSON in .net 3.5 This code seems to make it happy but then when it tried to deserialize it crashes.

What is it about the class LEGALLAND that is not quite right?

Public Class LEGALLAND Public success As Boolean Public type As String Public features As Feature End Class

{ "success":true, "type":"FeatureCollection", "features": [ { "type":"Feature", "properties": { "DLSSHORT":"2-2-2-W4", "QUARTER":"", "SECTION":"2", "TOWNSHIP":"2", "RANGE":"2", "MERIDIAN":"W4", "PROVINCE":"Alberta", "COUNTY":"CypressCounty", "LATITUDE":49.093639, "LONGITUDE":-110.173043, "ZOOM":14, "MGRS":"12UWV6037138194", "UTM":"12N5603725438195", "NTS":"B-14-G/72-E-1", "PID":"402002020" }, "geometry": { "type":"Polygon", "coordinates": [ [ [-110.162055,49.086400], [-110.162039,49.100866], [-110.184014,49.100879], [-110.184063,49.086410], [-110.162055,49.086400] ] ] } } ] }

5 Upvotes

2 comments sorted by

View all comments

1

u/CharlieMay VB.Net Intermediate Dec 12 '18

Can you show the other classes? More specifically how you are defining the Geometry object? I tried to work backward from your schema but I'm not very fluent with JSON and came up with the following result from my "assumed" class schema of the objects involved.

{
  "success": true,
  "type": "FeatureCollection",
  "features": {
    "type": "Feature",
    "properties": {
      "DLSSHORT": "2-2-2-W4",
      "QUARTER": "",
      "SECTION": "2",
      "TOWNSHIP": "2",
      "RANGE": "2",
      "MERIDIAN": "W4",
      "PROVINCE": "Alberta",
      "COUNTY": "CypressCounty",
      "LATITUDE": 49.09364,
      "LONGITUDE": -110.173042,
      "ZOOM": 14,
      "MGRS": "12UWV6037138194",
      "UTM": "12N5603725438195",
      "NTS": "B-14-G/72-E-1",
      "PID": "402002020"
    },
    "geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            -110.162055,
            49.0864
          ],
          [
            -110.162039,
            49.100866
          ],
          [
            -110.184014,
            49.100879
          ],
          [
            -110.184063,
            49.08641
          ],
          [
            -110.162055,
            49.0864
          ]
        ]
      ]
    }
  }
}

With the schema I produced, I was able to compare my inputs with what you had and the difference I found was that the [ before Features and the ] between the }'s at the end. I removed these two square brackets and was able to deserialize the JSON. Again, not sure what I did different so seeing the Feature, Properties and Geometry classes might help.