I'm trying to serialize a c# object to json to post to an external rest api.
The description to on property in my object was "LineItems is a list of LineItem"
So based on that, in C# i'd simply do this:
public List<LineItem> lineItems { get; set; }
public class LineItem
{
public string dealerProductCode { get; set; }
public string description { get; set; }
public string quantity { get; set; }
public string amount { get; set; }
}
Which would serialize into json like so:
{
//other properties etc
"lineItems":[
{
"dealerProductCode":"asdf",
"description":"asdf",
"quantity":"1",
"amount":"100"
}
]
}
However, they give two examples, one in xml and one in json.
json:
{
//other properties etc
"lineItems":{
"lineItem":[
{
"dealerProductCode":"asdf",
"description":"asdf",
"quantity":"1",
"amount":"100"
}
]
}
}
To me, this looks like... - An object called lineItems - That contains an array called lineItem - The first item in that array is a lineItem object
In the xml example it seems to make a lot more sense:
<lineItems>
<!--1 or more repetitions:-->
<lineItem>
<dealerProductCode>asdf</dealerProductCode>
<description>asdf</description>
<quantity>1</quantity>
<amount>1</amount>
</lineItem>
</lineItems>
How can I craft my C# to produce the json output they have in their example?