I have recently begun learning how to GET data from REST APIs, and I have encountered a problem.
This is my code so far:
<!-- language-all: lang-c# -->
using System...
using Newtonsoft.Json.Linq;
//I use JSON.NET V.6.0.7 for faster and less complicated parsing
...
...
WebClient client = new WebClient(); //Creates the client
Stream stream = client.OpenRead("INSERT API URL HERE"); //Calls the API
StreamReader reader = new StreamReader(stream); //Convert the information
dynamic data = JObject.Parse(reader.ReadToEnd()); //Parses JSON into an object
Console.WriteLine(data); //Writes out the information
}
}
}
So far my code works fine, and the only issue is that I get a lot of unnecessary information at once
I tried changing Console.WriteLine(data); to Console.WriteLine(data.author);
In an attempt to get all of the authors name, and instead I got an error saying
An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll
Why is that? And How can I Fix it?
I have tried searching for the answer and I did find a similar thread here, but it did not help me.
Any help will be much appreciated!
My native language is not in English, so I apologize any weird grammar use/misspelling.