- js.js
-
- function createxmlhttp()
- {
- var xmlhttp;
- if (window.ActiveXObject) {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- else if (window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- }
- return xmlhttp;
- }
-
- 3.htm
-
- <html>
-
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>新建网页 1</title>
-
- <script type="text/javascript" src="json/json.js"></script>
- <SCRIPT LANGUAGE="JavaScript" SRC="js/pjs.js"></SCRIPT>
- <SCRIPT LANGUAGE="JavaScript" SRC="js/zz.js"></SCRIPT>
- <script type="text/javascript">
- var xmlhttp;
-
- function Car(make, model, year, color)
- {
- this.make = make;
- this.model = model;
- this.year= year;
- this.color = color;
- }
- function getcarobject()
- {
- return new Car("中国","2312","2007","yellow");
- }
- function dojson()
- {
- var car = getcarobject();
- var carstr = car.toJSONString();
- alert(carstr);
-
- xmlhttp = null;
- xmlhttp = createxmlhttp();
- url = "WebForm1.aspx?dt="+new Date().getTime();
- xmlhttp.open("POST", url, true);
- xmlhttp.onreadystatechange = handleStateChange;
- xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
- xmlhttp.send(carstr);
- }
- function handleStateChange() {
- if (xmlhttp.readyState == 4) {
- if (xmlhttp.status == 200) {
- document.getElementById("testid").innerHTML = xmlhttp.responseText;
- alert("存档成功!");
- }
- }
- }
-
- function showJSON() {
- var user =
- {
- "username":"andy",
- "age":20,
- "info": { "tel": "123456", "cellphone": "98765"},
- "address":
- [
- {"city":"beijing","postcode":"222333"},
- {"city":"newyork","postcode":"555666"}
- ]
- }
- alert(user.username);
- alert(user.age);
- alert(user.info.cellphone);
- alert(user.address[0].city);
- alert(user.address[0].postcode);
- }
-
- function showmodJSON() {
- var user =
- {
- "username":"andy",
- "age":20,
- "info": { "tel": "123456", "cellphone": "98765"},
- "address":
- [
- {"city":"beijing","postcode":"222333"},
- {"city":"newyork","postcode":"555666"}
- ]
- }
-
- alert(user.username);
- alert(user.age);
- alert(user.info.cellphone);
- alert(user.address[0].city);
- alert(user.address[0].postcode);
-
- user.username = "Tom";
- alert(user.username);
- }
-
- function myEval() {
- var str = '{ "name": "Violet", "occupation": "character" }';
- var obj = eval('(' + str + ')');
- alert(obj.toJSONString());
- }
-
- function myEval2() {
- var str = '{ "name": "Violet", "occupation": "character" }';
- var obj = str.parseJSON();
- alert(obj.toJSONString());
- }
- </script>
- </head>
-
- <body>
-
- <form method="POST" action="WebForm1.aspx" target=_blank name="form1">
- <p><input type="button" value="显示" name="B3" onclick="showJSON()"></p>
- <P><input type="button" value="修改" name="B1" onclick="showmodJSON()"></P>
- <p><input type="button" value="showcar" name="B2" onclick="dojson()"></p>
- <p><input type="button" value="evar" name="evar" onclick="myEval()"></p>
- <p><input type="button" value="parsejoin" name="B5" onclick="myEval2()"></p>
- <p><input type="button" value="按钮" name="B6"></p>
- <p>
- <div id="testid">
- </div>
- </p>
- </form>
-
- </body>
-
- </html>
-
- webform1.aspx
-
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using Jayrock;
- using Jayrock.Json;
- using Jayrock.Json.Conversion;
- using System.IO;
- using System.Text;
-
- namespace licai
- {
-
-
-
- public class WebForm1 : System.Web.UI.Page
- {
- private void Page_Load(object sender, System.EventArgs e)
- {
-
- Stream instream = Page.Request.InputStream;
- BinaryReader br = new BinaryReader(instream, System.Text.Encoding.UTF8);
- byte[] byt = br.ReadBytes((int)instream.Length);
- string caj = System.Text.Encoding.UTF8.GetString(byt);
- par pa = (par)JsonConvert.Import(typeof(par),caj);
- Response.Write(pa.Make + pa.Year+ pa.Model+ pa.Color);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Response.End();
- }
- public class par
- {
- private string make, model, year, color;
-
- public string Make
- {
- get { return make; }
- set { make = value; }
- }
-
- public string Model
- {
- get { return model; }
- set { model = value; }
- }
-
- public string Year
- {
- get { return year; }
- set { year = value; }
- }
-
- public string Color
- {
- get { return color; }
- set { color = value; }
- }
-
- }
-
-
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
-
-
-
- InitializeComponent();
- base.OnInit(e);
- }
-
-
-
-
-
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }
ja
posted on
2008-11-07 10:33
阳春
阅读(
693)
评论()
收藏
举报