标签:des style blog http color io os java ar
1 @{ 2 ViewBag.Title = "GetStr"; 3 } 4 5 <html> 6 <head> 7 <title> </title> 8 <script type="text/javascript" src="~/Scripts/jquery-1.7.1.min.js"></script> 9 @* <script type="text/javascript" src="~/Scripts/jquery.jsonp-2.4.0.min.js"></script>*@ 10 <script type="text/javascript"> 11 12 $(function () { 13 $("#but").click(function () { 14 var o = new Object(); 15 o.id = 1; 16 o.name = "张三"; 17 o.age = 12; 18 o.hobby = "玩耍"; 19 var convertStr = JSON.stringify(o);//将js对象转换为json字符串 20 alert(convertStr); 21 var array = new Array(1,"张三",12,"玩耍"); 22 var arryConvertJson = JSON.stringify(array);//把数组转换为json字符串 23 alert(arryConvertJson); 24 $.ajax({ 25 url: "/home/getStr", 26 type: "post", 27 data: { "convertStr": arryConvertJson }, 28 async: true, 29 success: function (data) { }, 30 error: function () { }, 31 complete: function () { } 32 }) 33 }) 34 }) 35 </script> 36 </head> 37 <body> 38 39 <input type="button" id="but" value="提交" /> 40 </body> 41 </html>
1 public ActionResult GetStr(string convertStr="") 2 { 3 4 JavaScriptSerializer js = new JavaScriptSerializer(); 5 object[] o=(object[])js.DeserializeObject(convertStr); //将json字符串序列化成数组(json 中为数组) 6 var ss = o[0]; 7 // object p=js.Deserialize(convertStr, typeof(Person));//反序列化成对象 8 Person p1= js.Deserialize<Person>(convertStr); 9 return View(); 10 }
有了JSON.stringify(),处理json将变得更简单!!
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/luo-super/p/3991776.html