首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

怎么解析json(对象嵌套)

2012-10-21 
如何解析json(对象嵌套){RESPONSE:{DESCRIPTION:OK,SERIAL_NO:0,CODE:CLM_OK},DATA:{NAM

如何解析json(对象嵌套)
{"RESPONSE":{"DESCRIPTION":"OK","SERIAL_NO":"0","CODE":"CLM_OK"},"DATA":{"NAME":"ssss","LOYALTY_LIST":[{"MODIFY_DATETIME":"20110301","GROUP_ID":"A","SUB_ISSUER":"000010","CARD_TYPE":"0","REMARK3":[],"MEMBER_STATUS":"2","CARD_SUB":"1","SV_CARD":[],"APPLY_DATETIME":"20110301","STATUS":"8","CARD_OLD":[],"CAUSE":[],"MASTER_LOYALTY_ID":"95520000100023220000","SUSPEND_DATE":"20130301","CARD_BTYPE":"0","MERCHANTGROUP_ID":"00000010","MAST_NAME":"小兰","MAST_MEMBER_ID":"A","CREATE_DATETIME":"20110301","LOYALTY_ID":"95520000100023210000"},{"MODIFY_DATETIME":"20110301","GROUP_ID":"A","SUB_ISSUER":"000010","CARD_TYPE":"0","REMARK3":[],"MEMBER_STATUS":"2","CARD_SUB":"1","SV_CARD":[],"APPLY_DATETIME":"20050120","STATUS":"8","CARD_OLD":[],"CAUSE":[],"MASTER_LOYALTY_ID":"95520000100023240000","CARD_BTYPE":"0","SUSPEND_DATE":"20130301","MERCHANTGROUP_ID":"00000010","MAST_MEMBER_ID":"A","MAST_NAME":"小兰","LOYALTY_ID":"95520000100023240000","CREATE_DATETIME":"20050127"}]}}

[解决办法]
直接js解析可以用eval()函数,不过推荐使用jquery,eval有浏览器兼容的问题。

js:
var val=eval("("+data+")");
alert(val.RESPONSE);

jquery:
$.getJSON("路径","参数",function(data){
alert(data.RESPONSE);
});
[解决办法]
你知道所有的key值,下一个json的支持包
import net.sf.json.*;

之后

有现成的函数(一堆get各种value)。。

直接就能得到你想要的值。。。
[解决办法]

2,3楼给你把问题解决了 我来晚了,入股想了解跟多 http://www.happyalaric.com/archives/tag/json-shu-ju-ge-shi-jie-xi

探讨

直接js解析可以用eval()函数,不过推荐使用jquery,eval有浏览器兼容的问题。

js:
var val=eval("("+data+")");
alert(val.RESPONSE);

jquery:
$.getJSON("路径","参数",function(data){
alert(data.RESPONSE);
});

热点排行