1. 添加代碼段javascript
$.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; };
2.調用 JSON.stringify($("#form").serializeObject()) 轉換Json字符串java
其它:ios
1. 經過$("#form").serialize()能夠獲取到序列化的表單值字符串。數組
name1=1&name2=2&name3=3&name4=4&name5=5
2.經過$("#form").serializeArray()輸出以數組形式序列化表單值。this
[{name: "Radiosinline", value: "1"}, {name: "state", value: "1"}, {name: "visible", value: "0"}] {name: "Radiosinline", value: "1"} {name: "state", value: "1"} {name: "visible", value: "0"}
方式1:只是將Form序列化拼接成了簡單的字符串,並非JSON格式。spa
方式2:將Form表單序列化成JSON數組,須要再次轉換成JSON字符串。code