Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create get API using c# and sql server I like to pass parameter  get list value 



How create api for below type  
{  
   "ID":1000215620,
  "TestId":229,
  "status":yes,
      "Questions":[  
      {  
         "Qid":2,
         "Question":"",
         "Remarks":"test"
      }  , 
          "Qid":3,
         "Question":"",
         "Remarks":"dfdf"
   ]
}


What I have tried:

<pre>I want to create get API using c# and sql server I like to pass parameter  get list value 



How create api for below type  
{  
   "ID":1000215620,
  "TestId":229,
  "status":yes,
      "Questions":[  
      {  
         "Qid":2,
         "Question":"",
         "Remarks":"test"
      }  , 
          "Qid":3,
         "Question":"",
         "Remarks":"dfdf"
   ]
}
Posted
Updated 30-Nov-19 7:43am
Comments
DerekT-P 30-Nov-19 8:32am    
You'd need to tell us a great deal more before anyone can really help you.
What is at each end of the API (e.g. browser, desktop client, server) and how are they communicating?
What has the database got to do with anything?
What action are you wanting to invoke through the API?
What does the response look like?

As a final comment, just copy/pasting your question into the "What I have tried" box is adding zero information. Without any context at all there's precious little anyone could usefully say to solve whatever your problem is.

I would recommend that you start with one of the Web API Tutorials to get the basics and understanding of the technologies in use.
Tutorial: Create a web API with ASP.NET Core | Microsoft Docs[^]

Once you get an understanding and have all of your business rules worked out, you are going to have two simple classes similar to this
C#
public class Test {
	public int ID { get; set; }
	public int TestId { get; set; }
	public string Status { get; set; }
	public List<TestQuestion> Questions { get; set; }
}

public class TestQuestion {
	public int Qid { get; set; }
	public string Question { get; set; }
	public string Remarks { get; set; }
}
There are a few things that still need to be determined, such as how you what method are you going to talk to the database with- as is would be good for Entity Framework Code First.

Oh, one last thing; the sample JSON you posted is invalid- the second question should be wrapped in curly brackets as well.
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900