C# C# Streams and Data Processing Streaming Data on the Net Searching for News Headlines

Kevin Gates
Kevin Gates
14,793 Points

Documentation is out of date now, and no JSON to easily copy and paste.

Carling Kirk : is this something you can update? At least provide the initial JSON structure so we can easily update?

Things have changed on Microsoft's side so it is hard to follow along. Also, there is a 7day subscription free window, so I won't get to do this course ago after a week, unless I pay.

Kevin Gates
Kevin Gates
14,793 Points

I found this, which I think is the more accurate area for at least getting the JSON code: https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/csharp

2 Answers

to get a proper json response code as per your time, i recommend first writing the json code returned by the API using a simple method to output it as a string to a txt file like so;

    public static void WriteJsonToString(string PlayerName, string FilePath)

        var webClient = new WebClient();
        webClient.Headers.Add("Ocp-Apim-Subscription-Key", "your API Key");
        Byte[] playerInfo = 
        {0}&mkt=en-us", PlayerName));
        using (var stream = new MemoryStream(playerInfo))
        using (var writer = new StreamWriter(FilePath))
        using (var reader = new StreamReader(stream))

            string jsonString = reader.ReadToEnd();

call the method in main using any known soccer player's name like so;

WriteJsonToString("Christiano Ronaldo", "FileName"));

afterwards, go to the output folder and get the txt file created under the fileName that you specified, open the file with a notepad and copy that json code, then use an online json formatter or validator, i personally recommend https://jsonformatter.curiousconcept.com/

simply paste in the json code you copied from the txt file that your program created and it will format it into a proper Json format, then you can now use this json code with the visual studio's paste special - paste json as classes

Akio Ito
Akio Ito
11,019 Points

On a further Video, Carling Kirk shows you how VALIDATE and UPDATE any Json Code so that it can be Special Pasted / Paste JSON as classes into Visual Studio.

Copy the Json code from https://docs.microsoft.com/en-us/azure/cognitive-services/bing-news-search/concepts/search-for-news#get-general-news

Type it into https://jsonlint.com/

Remove any unwanted Json Code.

Now it is ready to paste into Visual Studio.