当前位置: 代码迷 >> J2EE >> 怎么解析json(对象嵌套)
  详细解决方案

怎么解析json(对象嵌套)

热度:86   发布时间:2016-04-22 00:31:48.0
如何解析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);
});
  相关解决方案