为什么从Post方法返回的元素的顺序在Postman和Lambda之间有所不同?

时间:2015-01-08 20:21:53

标签: c# json rest xml-serialization postman

当我从Postman调用REST方法时,将按以下顺序返回数据:

enter image description here

IOW:

VendorId
VendorItemID
Id
PackSize

当我从客户端应用程序调用REST方法时:

private IEnumerable<VendorItem> GetCollectionOfVendorItems()
{
    ArrayList arrList = 
FetchDataFromServer("http://localhost:21608/api/vendoritem/getall");
    String contents = "<VendorItems>";
    foreach (String s in arrList)
    {
        contents += s;
    }
    contents += "</VendorItems>";
    String unwantedPreamble = "<ArrayOfVendorItem xmlns:i=\"http://www.w3.org/2001/XMLSchema-
instance\" xmlns=\"http://schemas.datacontract.org/2004/07/CStore.DomainModels.HHS\">";
    contents = contents.Replace(unwantedPreamble, String.Empty);
    contents = contents.Replace("</ArrayOfVendorItem>", String.Empty);
    XDocument xmlDoc = XDocument.Parse(contents);
    IEnumerable<VendorItem> vendorItems = xmlDoc.Descendants("VendorItem").Select(x => 
GetVendorItemForXMLElement(x));
    return vendorItems;
}

private static VendorItem GetVendorItemForXMLElement(XElement vendor)
{
    return new VendorItem
    {
        Id = vendor.Element("Id").Value,
        PackSize = Convert.ToInt32(vendor.Element("PackSize").Value),
        VendorId = vendor.Element("VendorId").Value,
        VendorItemID = vendor.Element("VendorItemID").Value
        //VendorId = vendor.Element("VendorId").Value,
        //VendorItemID = vendor.Element("VendorItemID").Value,
        //Id = vendor.Element("Id").Value,
        //PackSize = Convert.ToInt32(vendor.Element("PackSize").Value)
    };
}

public class VendorItem
{
    public string Id { get; set; }
    public int PackSize { get; set; }
    public string VendorId { get; set; }
    public string VendorItemID { get; set; }
    public String siteNum { get; set; }

    //public string VendorId { get; set; }
    //public string VendorItemID { get; set; }
    //public string Id { get; set; }
    //public int PackSize { get; set; }
    //public String siteNum { get; set; }
}

...它按此顺序返回元素:

enter image description here

(你听说过Big Data,那是Wavy Gravy的数据)

IOW:

Id
PackSize
VendorId
VendorItemID

即使班级中的成员顺序与邮递员的回报相符,也没有区别;无论哪种方式,我先得到Id等等。

为什么会这样?这似乎并不重要,但我错了吗?

c#REST postman xml json

0 个答案:

没有答案