Link to home
Start Free TrialLog in
Avatar of zipnotic
zipnoticFlag for United States of America

asked on

Deserialize JSON array VB.Net problem

Hello,

First time JSON project in WinForms using VS 2015 and VB.Net along with Newtonsoft.Json.

Having a heck of a time figuring out how to deserialize this array.  I used the copy paste as special in VS 2015 to create the structure and I've been playing around with it some for hours.  Plenty of searching and examples later I am no further along.  I'm guessing I just don't have the right list or array defined but can someone guide me in the right direction?  Either I get the standard deserializing error of

To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.

OR, I'm getting the property number of elements in "Class1" but no data/everythings empty.

Code followed by JSON sample:


Dim Class1() As Results = JsonConvert.DeserializeObject(Of Results())(FullJSON)


Public Class Results
        Public Property Results As List(Of Class1)
    End Class

    Public Class Class1
        Public Property meta As Meta
        Public Property county As County
        Public Property caseNo As String
        Public Property filingDate As String
        Public Property status As Status
        Public Property isSeal As Boolean
        Public Property searchedParty As Searchedparty
        Public Property caption As String
        Public Property lastModified As Date
    End Class

    Public Class Meta
        Public Property href As String
        Public Property mediaType As String
    End Class

    Public Class County
        Public Property meta As Meta1
        Public Property countyNo As Integer
    End Class

    Public Class Meta1
        Public Property href As String
        Public Property mediaType As String
    End Class

    Public Class Status
        Public Property meta As Meta2
        Public Property statusCode As String
    End Class

    Public Class Meta2
        Public Property href As String
        Public Property mediaType As String
    End Class

    Public Class Searchedparty
        Public Property name As _Name
        Public Property dob As String
    End Class

    Public Class _Name
        Public Property first As String
        Public Property middle As String
        Public Property last As String
    End Class

Open in new window


JSON:

[
  {
    "meta": {
      "href": "https://website/api/1418",
      "mediaType": "application/json"
    },
    "county": {
      "meta": {
        "href": "https://website/data/144",
        "mediaType": "application/json"
      },
      "countyNo": 144
    },
    "caseNo": "1418",
    "filingDate": "2011-12-01",
    "status": {
      "meta": {
        "href": "https://website/statusCodes/CL",
        "mediaType": "application/json"
      },
      "statusCode": "CL"
    },
    "isSeal": false,
    "searchedParty": {
      "name": {
        "first": "John",
        "middle": "J.",
        "last": "Doe"
      },
      "dob": "1952-07-01"
    },
    "caption": "Someone named John J Doe",
    "lastModified": "2013-11-08T13:52:51.477Z"
  },
  {
    "meta": {
      "href": "https://website/api/860",
      "mediaType": "application/json"
    },
    "county": {
      "meta": {
        "href": "https://website/data/144",
        "mediaType": "application/json"
      },
      "countyNo": 144
    },
    "caseNo": "860",
    "filingDate": "2013-02-14",
    "status": {
      "meta": {
        "href": "https://website/statusCodes/CL",
        "mediaType": "application/json"
      },
      "statusCode": "CL"
    },
    "isSeal": false,
    "searchedParty": {
      "name": {
        "first": "John",
        "middle": "J.",
        "last": "Doe"
      },
      "dob": "1952-07-01"
    },
    "caption": "Someone named John J Doe",
    "lastModified": "2014-11-08T13:16:24.443Z"
  },
  {
    "meta": {
      "href": "https://website/185",
      "mediaType": "application/json"
    },
    "county": {
      "meta": {
        "href": "https://website/data/132",
        "mediaType": "application/json"
      },
      "countyNo": 132
    },
    "caseNo": "185",
    "filingDate": "2009-02-12",
    "status": {
      "meta": {
        "href": "https://website/statusCodes/CL",
        "mediaType": "application/json"
      },
      "statusCode": "CL"
    },
    "isSeal": false,
    "searchedParty": {
      "name": {
        "first": "John",
        "middle": "J.",
        "last": "Doe"
      },
      "dob": "1952-07-01"
    },
    "caption": "Someone named John J. Doe",
    "lastModified": "2013-05-08T15:47:40.876Z"
   }
  ]
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zipnotic

ASKER

Geeeeezzzz,  that was easy....I was so close.  And I'd swear I tried that syntax at some point....

Thanks a million.

Zip
Fast and accurate response.  Very happy!