<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="/scripts/jquery/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(function () { var jsonObj = {}; jsonObj.a = "aaaa"; var $input = $("input[id^='List_']"); $input.each(function () { var id = $(this).attr("id").replace("List_", ""); jsonObj[id] = "ccccc"; //$(this).val(); }) var str = JSON.stringify(jsonObj); alert(str); }) </script> </head> <body> <form id="form1" runat="server"> <div> <input id="List_nick" value="abc" /> <input id="List_keyword" value="keyword" /> </div> </form> </body> </html>
alert 效果:{"a":"aaaa","nick":"ccccc","keyword":"ccccc"}
后台可以使用NewTonJson.net 接收json字符串