Sending a WebClient() request to a Web API, my API call is returning with data which I am deserialising with JsonConvert.DeserializeObject().
The object then has properties which I cannot seem to reference.
var coursesParams = new NameValueCollection();
coursesParams.Add("grant_type", "password");
coursesParams.Add("client_id", "ContentUpload");
coursesParams.Add("client_secret", "2dfe381b4e620fff9b4fa05997e26d141d9c2c6d");
coursesParams.Add("username", "isadmin");
coursesParams.Add("password", "xxxxxxxxx");
WebClient coursesRequest = new WebClient();
coursesRequest.Encoding = Encoding.UTF8;
coursesRequest.Headers.Add("Authorization", "Bearer " + x.access_token);
coursesRequest.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
coursesRequest.Headers.Add("Accept-Language", "en-US");
coursesRequest.Headers.Add("Accept", "text/html, application/xhtml+xml, */*");
coursesRequest.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
var coursesData = coursesRequest.UploadValues("https://xxx.yyyyyyyyyy.com/api/course/courses", "POST", coursesParams);
var y = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(coursesData));
System.Console.ReadKey();
When I pause the program and examine the y
object in the debugger, it shows properties, but I cannot reference any of them. Screen image:
And, any attempt to reference (or read) these properties results in an error:
y.ChildrenTokens
error CS1061: 'object' does not contain a definition for 'ChildrenTokens' and no accessible extension method 'ChildrenTokens' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
y.Count
error CS1061: 'object' does not contain a definition for 'Count' and no accessible extension method 'Count' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
What am I doing (or seeing) wrong? Are these properties simply not accesssible? Or am I referencing them incorrectly?