0

I want to get data from this api and import data into a excel sheet using c#

and also want to convert that jasonContent1 to csv format. thank you..

private void button3_Click(object sender, RibbonControlEventArgs e)
{
    string url = String.Format("https://jsonplaceholder.typicode.com/users?id=1");
    WebRequest webRequest = WebRequest.Create(url);

    webRequest.Method = "GET";
    HttpWebResponse respObj = null;
    respObj = (HttpWebResponse)webRequest.GetResponse();

    string resultTest1 = null;
    using (Stream stream = respObj.GetResponseStream())
    {
        StreamReader reader = new StreamReader(stream);
        resultTest1 = reader.ReadToEnd();
        //string json = resultTest1.Trim();
        // DataSet jsonContent = JsonConvert.DeserializeObject<DataSet>(json);
        var jsonContent1 = JsonConvert.DeserializeObject(resultTest1);


        reader.Close();

    }
}
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
trevor
  • 1
  • 4
  • Did you try to run the code under the debugger? What values do you see? – Eugene Astafiev Mar 31 '22 at 15:27
  • "[\n {\n \"id\": 1,\n \"name\": \"Leanne Graham\",\n \"username\": \"Bret\",\n \"email\": \"Sincere@april.biz\",\n \"address\": {\n \"street\": \"Kulas Light\",\n \"suite\": \"Apt. 556\",\n \"city\": \"Gwenborough\",\n \"zipcode\": \"92998-3874\",\n \"geo\": {\n \"lat\": \"-37.3159\",\n \"lng\": \"81.1496\"\n }\n },\n \"phone\": \"1-770-736-8031 x56442\",\n \"website\": \"hildegard.org\",\n \"company\": {\n \"name\": \"Romaguera-Crona\",\n \"catchPhrase\": \"Multi-layered client-server neural-net\",\n – trevor Apr 01 '22 at 01:06
  • See [JSON string to CSV and CSV to JSON conversion in c#](https://stackoverflow.com/questions/36274948/json-string-to-csv-and-csv-to-json-conversion-in-c-sharp) – Eugene Astafiev Apr 01 '22 at 08:09

0 Answers0