js格式化时间为JSON格式 ajax提交 后台处理

时间:2022-11-02 16:07:22

var effectRow = new Object();
if ($('#grd_infos').datagrid('getChanges').length) {
    var update = $('#grd_infos').datagrid('getChanges', "updated");
    if (update.length) {
        //var jsonArray = mini.decode(update);
        //var jsonArray =  JSON.stringify(update);
        for (var i = 0; i < update.length; i++) {
            for (var key in update[i]) {

//如果是时间字段
                if (key.toString() == "…" || key.toString() == "…"
                    || key.toString() == "…" || key.toString() == "Time") {
                    update[i][key] = convertDateToJSONDate(update[i][key]);
                }
            }
        }

effectRow["updated"] = JSON.stringify(update);
        }
    }

$.post("/url….", effectRow, function (data) {
                   if (data) {
                       $.messager.alert('', data, 'info');
                       window.open("Machine_Repair", "_self");
                   }
               }, "JSON").error(function () {
                   $.messager.alert("提示", "提交错误了!");
               });

List<Repair_Entry> listUpdated  =new List<Repair_Entry>();

if (Request["updated"] != null && Request["updated"].Trim() != "")
    jsonUpdate = Request["updated"];

if (jsonUpdate != "")
{

listUpdated = JsonDeserialize<List<Repair_Entry>>(jsonUpdate);
}

private T JsonDeserialize<T>(string jsonString)
{
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
    T obj = (T)ser.ReadObject(ms);
    return obj;
}