sunny kumar

sunny kumar

  • 1.7k
  • 173
  • 1.5k

Storing Api data response in database

Oct 16 2019 6:23 AM
I am able to fetch api data , but the response is coming in collection form, how should i loop through first array and store only that information . The response which i am receiving from api is as follows:
 
{"ngodetails":[{"id":"DL\/2017\/0165260","name":"\tASSOCIATION FOR SOCIAL SERVICE AND REHABILITATION OF THE AGED ASSRA","registrationNumber":"42540 OF 2002","panNumber":"Available","panVerifyStatus":"V"}],"memberdetails":[{"name":"NAMITA SAHOO","designation":"President","aadhaarNumber":"Available","aadhaarVerifyStatus":"V","panNumber":"Available","panVerifyStatus":"V","LastUpdated":"13-10-2017 07:00:17"},{"name":"PRASHANTA GHADAI","designation":"Vice President","aadhaarNumber":"Available","aadhaarVerifyStatus":"V","panNumber":"Available","panVerifyStatus":"V","LastUpdated":"13-10-2017 07:00:09"},{"name":"ANIL KUMAR ROY","designation":"Secretary","aadhaarNumber":"Available","aadhaarVerifyStatus":"V","panNumber":"Available","panVerifyStatus":"V","LastUpdated":"14-10-2017 11:36:20"}]}
  1. public ActionResult Index()  
  2. {  
  3. List<ngodarpan> ngo = new List<ngodarpan>();  
  4. string baseurl = "https://ngodarpan.gov.in/ngodarpanws_ndci/apin/getngo/DL_2017_0165260";  
  5. using (var client = new HttpClient())  
  6. {  
  7. client.BaseAddress = new Uri(baseurl);  
  8. client.DefaultRequestHeaders.Clear();  
  9. client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));  
  10. HttpResponseMessage Res = client.GetAsync(baseurl).Result;  
  11. if (Res.IsSuccessStatusCode)  
  12. {  
  13. var response = Res.Content.ReadAsStringAsync().Result;  
  14. ngo = JsonConvert.DeserializeObject<List<ngodarpan>>(response);  
  15. }  
  16. return View(ngo);  
  17. }  
  18. }  
  19. @model IEnumerable<eofficeWepApi.Models.ngodarpan>  
  20. @{  
  21. ViewBag.Title = "Index";  
  22. }  
  23. <h2>Index</h2>  
  24. <table>  
  25. <thead>  
  26. <tr>  
  27. <th>Id</th>  
  28. <th>Name</th>  
  29. <th>Registration Number</th>  
  30. <th>PanNumber</th>  
  31. <th>PanVerifyStatus</th>  
  32. </tr>  
  33. </thead>  
  34. <tbody>  
  35. @foreach(var i in Model)  
  36. {  
  37. <tr>  
  38. <td>@i.id</td>  
  39. <td>@i.name</td>  
  40. <td>@i.registrationnumber</td>  
  41. <td>@i.panNumber</td>  
  42. <td>@i.panVerifyStatus</td>  
  43. </tr>  
  44. }  
  45. </tbody>  
  46. </table>  

Answers (2)