How to deserialize JSON data list into .NET generic collection

I am working with a REST data source.  Single row returns aren't a problem as I can deserialize them using something like:
 JsonConvert.DeserializeObject(Of myInstantiatedClass)(httpResponseContent)

Retrieving a data list isn't a problem either.  But I am unable to deserialize it (using Newtonsoft.Json) into a .NET LIST collection.   A view of the simplified data looks like:
{
	"results":[
	{
		"id":"_198711_1"
	},
	{
		"id":"_198710_1"
	},
	]
}

Open in new window


I am using vb.net in this project but please feel free to send hints in c#!  I've tried various things including IEnumerate.  Simplifed snippet of the original code looks like this:
Public Class myClass
        Public Property id As String
End Class

...

 Dim myInstantiatedClass As New List(Of myClass)
        Dim response = Await client.GetAsync(Uri)
        If response.IsSuccessStatusCode Then
            Dim httpResponseContent = Await response.Content.ReadAsStringAsync()
            Try
                ' NEXT LINE IS WHERE ERRORS ARE THROWN 
                myInstantiatedClass = JsonConvert.DeserializeObject(Of List(Of InstantiatedClass ))(httpResponseContent)
            Catch jsonException As Newtonsoft.Json.JsonSerializationException
                Dim s As String = jsonException.Message
            End Try
        End If

Open in new window


The error code (using original variable and class names) reads:
"Cannot deserialize the current JSON object (e.g. {""name"":""value""}) into type 'System.Collections.Generic.List`1[BbRestApiExplorer.CourseGradeColumn]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly." 
"To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object." 
"Path 'results', line 1, position 11."

Open in new window


Any thoughts?   Thank you for your time.
LVL 1
RichardKlineAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi RichardKline;

In Visual Studio you can create the classes needed to deserialize a Json object into .Net objects. You can do this by first copying the Json object to the clipboard then place your cursor in a code window where you want to have the new classes to be pasted into. Then on the main menu on the IDE click on Edit -> Paste Special -> Paste JSON As Classes. This will paste the classes needed in parsing the JSON. This will work well with NewtonSoft.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.