<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
request.setAttribute("base", request.getContextPath());
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>decode和encode的介绍</title>
<link rel="stylesheet" type="text/css" href="${base}/ext/resources/css/ext-all.css" />
<script type="text/javascript" src="${base}/ext/ext-base.js"></script>
<script type="text/javascript" src="${base}/ext/ext-all.js"></script>
<script type="text/javascript" src="${base}/ext/ext-lang-zh_CN.js"></script><!--中文映射-->
<script type="text/javascript">
function ready(){
//定义一个json字符串
var 小李子="{姓名:'李子', 性别:'男',籍贯:'北京'}";
//将json字符串转换为对象,以后调用直接对象.属性就ok啦
var person=Ext.decode(小李子);
var name=person.姓名;//获取对象的姓名属性
var sex=person.性别;//获取对象的性别属性
var home=person.籍贯;//获取对象的籍贯属性
var result="信息:姓名是:"+name+",性别:"+sex+",籍贯:"+home;
Ext.Msg.alert("小李子",result);
var Object2Json=function(){//对象转为json字符串函数
var json=Ext.encode(person);//将对象转为json格式的数据字符串
Ext.Msg.alert("对象转为json字符串",json);
}
setTimeout(Object2Json,5000);//在5秒钟后调用函数并执行
}
Ext.onReady(ready) ;//参数为定义的函数,onReady是程序的入口
</script>
</head>
<body>
</body>
</html>