【此案例为自动产生的随机数】
对象:
{a1:180,a2:721, a3:574}
序列化传值:将对象转化为Json字符串
1 public ActionResult Val2() 2 { 3 Random rd = new Random(); 4 var num1 = rd.Next(1, 1000); 5 var num2 = rd.Next(10, 1000); 6 var num3= rd.Next(100, 1000); 7 8 var msg = new 9 { 10 a1 = num1, 11 a2 = num2, 12 a3 = num3, 13 }; 14 JavaScriptSerializer js = new JavaScriptSerializer(); 15 16 return Content(js.Serialize(msg)); 17 }
进行处理:JSON.parse(data)
反序列化后:【把JSON字符串反序列化成对象】