zoukankan      html  css  js  c++  java
  • WebApi XML,Json格式自定义,IEnumerable<T>,ArrayOf

    global.ascx中application-start()

    GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;

            [XmlIgnore] //生成XML结果的时候,忽略该字段
            [JsonIgnore] //生成JSON结果的时候,忽略该字段
            public Guid Id { get; set; }

    当程序需要返回List<T>或者IEnumerable<T>多记录的时候,为了避免出现ArrayOf为XMLROOT的情况,需要自定义一个类,如下

    namespace ElegantWM.DTO
    {
        [XmlRoot("EcResult")]
        //[XmlArrayItem("SmsReceived")]
        //[CollectionDataContract(Name = "EcResult", ItemName = "SmsReceived", Namespace = "")]
        public class EcSmsReceivedResult : List<EC_SmsReceived>
        {
    
        }
    }
     [HttpPost]
            public EcSmsReceivedResult SmsReply()
            {
                EC_Customer customer = CheckCustomer();
                var list = WMFactory.SmsReceived.GetSmsReceived(customer.Id);
                EcSmsReceivedResult rst=new EcSmsReceivedResult();
                rst.AddRange(list);
                return rst;
            }
  • 相关阅读:
    [leetcode]66Plus One
    [leetcode]64Minimum Path Sum 动态规划
    [leetcode]62.UniquePaths
    [leetcode]54. Spiral Matrix2生成螺旋数组
    Keywords Search HDU
    Division HDU
    Naming Babies UVA
    Pearls POJ
    K-Anonymous Sequence POJ
    Post Office POJ
  • 原文地址:https://www.cnblogs.com/qidian10/p/3627621.html
Copyright © 2011-2022 走看看