Hello guys,
I have been working on a web service, I did everything based on json, and everything was going well, but the client wants to send data in XML.
So, I was planning to convert XML to JSON on the web client, in that way I didn't need to change the code on my web service.
However, when I convert XML to JSON sometimes it ignore that fact that Items or Boxes are arrays.
If I have 2 container on the XML it will identify that it is an array, but if I have one it will send as an unique object.
Like in the example below. The first box has 2 items so it did convert correctly, but the second box has only one, and it return without [ .
When I receive these values on the web service it will miss these values when I do the deserialization because my contract class look like this
[
DataMemberAttribute('Items'),
DataCollectionAttribute(Types::Class, classStr(ItemsContract))
]
public List parmItems(List _items = items)
{
items = _items;
return items;
}
{
"Shipment": {
"ShipmentId": "Value",
"Boxes": [
{
"BoxID": "001",
"Weight": "1",
"Items": [
{
"ItemId": "WHSSerialized",
"Qty": "1"
},
{
"ItemId": "WHSSerialized",
"Qty": "1"
}
]
},
{
"BoxID": "002",
"Weight": "1",
"Items": {
"ItemId": "WHSSerialized",
"Qty": "1"
}
}
]
}
}
Any ideas?
Thanks