添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
含蓄的火锅  ·  php - curl ...·  1 年前    · 
善良的勺子  ·  運算式·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm sure there are some posts talking about it but so far, nothing works in my case. I get data from an api and I read it within a console application in C# for testing purpose. My end goal is to call the data from the API and store the attributes ("analyst" for ex) somewhere where I could pick some of them and dysplay them within a winform app' (I think mostly through a Datagridview than a webbrowser but I'm not sure). I understand I need Json.net but as I use the ReadAsStringAsync() method I'm not sure about the object type I use anymore. Here is my code:

// Get the response from the API
        using (var client = new HttpClient())
                var response = client.SendAsync(httpRequestMessage).Result;
                //Console.WriteLine(response.ToString());
                HttpContent responseContent = response.Content;
                var responsedata = responseContent.ReadAsStringAsync();
                //Console.WriteLine(responseContent);
                string data = responsedata.Result;
                var BS = JsonConvert.DeserializeObject<dynamic>(data);
                string analyst = BS.analyst;
                Console.WriteLine(analyst);
                Console.ReadKey();
            catch (HttpRequestException e)
                Console.WriteLine("\nException Caught!");
                Console.WriteLine($"Message: {e.Message}");

I got an object "data" like this :

"result": "3_yr_proj_eps_cagr_prcntg": 47.0, "analyst": "Jones Dow", "analyst_email": "Dow.Jones@Theprovider.com", "business_summary": "<p>COMPANY OVERVIEW. Dow Inc. was formed on April 1, 2019, following the spin- off of the company from DowDupont".

And I just want to display "analyst" into my datagridview when I click on a button but so far my variable "analyst" is null meaning the porgramm does not see the value "Jones Dow"...

I'm kind of lost within all the information I could read about the topic, any help would be appreciated. Thanks

Perfect @Andy ! Thanks so at the end it was indeed a json object I deserialized into a .NET object. Now I guess I simply need to send the different attributes within my datagridview ! Thank you so much – James06 Apr 13, 2021 at 14:41

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.