1.serialize()方法

  格式:var data = $("form").serialize();

  功能:将表单内容序列化成一个字符串。

  这样在ajax提交表单数据时,就不用一一列举出每一个参数。只需将data参数设置为 $("form").serialize() 即可。

2.serializeArray()方法

  格式:var jsonData = $("form").serializeArray();

  功能:将页面表单序列化成一个JSON结构的对象。注意不是JSON字符串。

  比如,[{"name":"lihui", "age":"20"},{...}] 获取数据为 jsonData[0].name

/// <summary>
        /// Form格式序列化
        /// </summary>
        /// <param name="FormParas"></param>
        /// <returns></returns>
        public static String ConvertFormParasToJsonStr(string FormParas)
        {
            String[] f = FormParas.Split('&');

            Hashtable hash = new Hashtable();
            foreach (var item in f)
            {
                if (item.Contains("="))
                {
                    var key = MyUrlDeCode(item.Substring(0, item.IndexOf("=")), Encoding.UTF8);
                    var value = item.Substring(item.IndexOf("=") + 1);


                    if (hash.ContainsKey(key))
                    {
                        var newvalue = hash[key] + "," + value;
                        hash.Remove(key);
                        hash.Add(key, MyUrlDeCode(newvalue, Encoding.UTF8));
                    }
                    else
                    {
                        hash.Add(key, MyUrlDeCode(value, Encoding.UTF8));
                    }
                }
            }
            string d = Newtonsoft.Json.JsonConvert.SerializeObject(hash);
            return d;
        }


public static string MyUrlDeCode(string str, Encoding encoding)

{
    if (encoding == null)
    {
        Encoding utf8 = Encoding.UTF8;
        //首先用utf-8进行解码                    
        string code = HttpUtility.UrlDecode(str.ToUpper(), utf8);
        //将已经解码的字符再次进行编码.
        string encode = HttpUtility.UrlEncode(code, utf8).ToUpper();
        if (str == encode)
            encoding = Encoding.UTF8;
        else
            encoding = Encoding.GetEncoding("gb2312");
    }
    return HttpUtility.UrlDecode(str, encoding);
}

var jsonStr = Common.ConvertFormParasToJsonStr(obj);
            Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr);
            //报价单头信息
            Header = new SD_BJKOs();
            Header.CusRPO = Convert.ToString(jobject.GetValue("KO_CusRPO") == null ? string.Empty : jobject.GetValue("KO_CusRPO"));
            Header.SoldToParty = Convert.ToString(jobject.GetValue("KO_SoldToParty") == null ? string.Empty : jobject.GetValue("KO_SoldToParty"));
            Header.CusRPODate = Convert.ToString(jobject.GetValue("KO_CusRPODate") == null ? string.Empty : jobject.GetValue("KO_CusRPODate"));
            Header.RDDAT = Convert.ToString(jobject.GetValue("KO_RDDAT") == null ? string.Empty : jobject.GetValue("KO_RDDAT"));
            Header.CUSRPJNO = Convert.ToString(jobject.GetValue("KO_CUSRPJNO") == null ? string.Empty : jobject.GetValue("KO_CUSRPJNO"));
            Header.KOEIN = Convert.ToString(jobject.GetValue("KO_KOEIN") == null ? string.Empty : jobject.GetValue("KO_KOEIN"));
            Header.WERKS = Convert.ToString(jobject.GetValue("KO_WERKS") == null ? string.Empty : jobject.GetValue("KO_WERKS"));

            Item = new List<SD_BJPOs>();
            var BJSOR = Convert.ToString(jobject.GetValue("PO_BJSOR"));
            var BJSORlst = BJSOR.Split(',');
            var MATNR = Convert.ToString(jobject.GetValue("PO_MATNR"));
            var MATNRlst = MATNR.Split(',');
            var ODQTY = Convert.ToString(jobject.GetValue("PO_ODQTY"));
            var ODQTYlst = ODQTY.Split(',');
            var ODUNIT = Convert.ToString(jobject.GetValue("PO_ODUNIT"));
            var ODUNITlst = ODUNIT.Split(',');
            var NETPR = Convert.ToString(jobject.GetValue("PO_NETPR"));
            var NETPRlst = NETPR.Split(',');
            var MEPTR = Convert.ToString(jobject.GetValue("PO_METPR"));
            var MEPTRlst = MEPTR.Split(',');
            var WERKS = Convert.ToString(jobject.GetValue("PO_WERKS"));
            var WERKSlst = MEPTR.Split(',');
            //var MDate = Convert.ToString(jobject.GetValue("MDate"));
            //var MDatelst = MDate.Split(',');
            //var MUser = Convert.ToString(jobject.GetValue("MUser"));
            //var MUserlst = MDate.Split(',');
            for (int i = 0; i < BJSORlst.Count(); i++)
            {
                SD_BJPOs sb = new SD_BJPOs
                {
                    BJSOR = BJSORlst[i] == "" ? string.Empty : BJSORlst[i],
                    MATNR = MATNRlst[i] == "" ? string.Empty : MATNRlst[i],
                    ODQTY = Convert.ToDecimal(ODQTYlst[i] == "" ? "0" : ODQTYlst[i]),
                    ODUNIT = ODUNITlst[i] == "" ? string.Empty : ODUNITlst[i],
                    NETPR = Convert.ToDecimal(NETPRlst[i] == "" ? "0" : NETPRlst[i]),
                    METPR = Convert.ToDecimal(MEPTRlst[i] == "" ? "0" : MEPTRlst[i]),
                    WERKS = WERKSlst[i] == "" ? string.Empty : WERKSlst[i],
                    //MDate = Convert.ToDateTime(MDatelst[i]),
                    //MUser = MUserlst[i]
                };
                Item.Add(sb);
            }