Reputation:
I been working on this API that I would like to remove the top element but I am not sure the best way to do it. Do I need to
public CARlinesResponse GetCarslinesResponse (string accessKey)
CARlinesResponse CAR = new CARlinesResponse();
CarlineManager cm = new CarlineManager ();
CarslineReportParameters cr= new CarslineReportParameters ();
car.lines = GetGuidelineViewModel(cm.GetCarslinesResponse (cr));
return CAR;
//return CAR.CARline;
}
Model
namespace WebApi.Models
{
public class CARlinesResponse
{
public CARline[] CARlines{ get; set; }
}
Output I am looking for
[
{
"Id": "9c996a94-5a61-42b4-953e-34134f6332b3",
"Title": "Jeep",
"Version": "grand cherokee",
}
]
Like to remove the top level cars
{
"CARline": [
{
"Id": "9c996a94-5a61-42b4-953e-34134f6332b3",
"Title": "Jeep",
"Version": "grand cherokee"
}
Upvotes: 0
Views: 76
Reputation: 61849
I would expect that returning the Carline
property, with an appropriately amended method signature, should do the trick.
public CARline[] GetCarslinesResponse (string accessKey)
{
CARlinesResponse Car = new CARlinesResponse();
CarlineManager cm = new CarlineManager ();
CarslineReportParameters cr= new CarslineReportParameters ();
Car.Carlines = GetGuidelineViewModel(cm.GetCarslinesResponse (cr));
return Car.CARlines;
}
Of course any code which calls the method might also need to be changed, it depends what exactly you've implemented.
P.S. It seems you could actually shorten this to
public CARline[] GetCarslinesResponse (string accessKey)
{
CarlineManager cm = new CarlineManager ();
CarslineReportParameters cr = new CarslineReportParameters ();
return GetGuidelineViewModel(cm.GetCarslinesResponse (cr));
}
and dispense with the CarLinesRepsonse object entirely.
Upvotes: 1