json学习 我相信一定对大家有帮助

http://hi.baidu.com/coolcooldool/blog/item/a737888fdc485cf0513d9287.html json所有知识

http://yxgyh.iteye.com/blog/392657
http://www.iteye.com/topic/295083
http://www.cnblogs.com/known/archive/2009/06/08/1417128.html
自己练习的例子:
Model 对象
private Integer id;
private String name;
private String status;
private Type type;
Type 对象
private Integer id;
private String typeName;
action层代码
Type type = new Type();
type.setId(2);
type.setTypeName("yyyy");

List<Model> list = new ArrayList<Model>();
Model m = new Model(1,"haiwei", "true");
m.setType(type);
list.add(m);
Model m1 = new Model(2,"guoyu", "false");
m1.setType(type);
list.add(m1);

JSONArray ja = JSONArray.fromObject(list);
System.out.println(ja.toString());
MessageUtils.outputJSONResult("{[[color=red]list[/color]:"+ja.toString()+"}", response); 结果返回页面

jsp文件
<script type="text/javascript" src="${pageContext.request.contextPath}/js/common/jquery-1.3.1.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("${pageContext.request.contextPath}/shop/main/getJson.do", function(json){
var html = "";
$.each(json.[color=red]list[/color], function(i, n){
alert(i);
html += "<option value=" + n.id + ">" + n.name +"--"+n.status+ "</option>";
var array = n.type;
alert(array['id']+array['typeName']);
});
alert(html);
});
})
</script>

经过刚才的练习才发现,json对象里面的list必须和封装中list必须一致,否则找不见对象,我在公司那个方式是不是也是因为这个才没出现结果的呢,明天我得试试去
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值