日期:2014-05-16  浏览次数:20413 次

JSON数据获取
获取到一个JSON字符串如下:
{"FUNlist":[{"FunBh":1,"Url":"www.sohu.com","Xh":1,"ID":"f3994af5-36be39e3-0136-be39ee7e-0001","F_FUNBh":0,"FunName":"学习计划"}],"POFlist":[{"ORER_BH":1,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":1,"ID":"f3994ab0-36c88bc8-0136-c88bd15e-0001"},{"ORER_BH":2,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":2,"ID":"f3994ab0-36c88bc8-0136-c88bd19d-0002"},{"ORER_BH":3,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":3,"ID":"f3994ab0-36c88bc8-0136-c88bd19d-0003"}]}
到JSP页面怎么能把里面的数据获取到?
首先说明一下。我没用 var obj = Ext.util.JSON.decode(right);
var right = '<%=session.getAttribute("loginerRight")%>'; 
alert(right);
var obj = Ext.util.JSON.decode(right);
var username='<%=session.getAttribute("userName")%>'
var userid='<%=session.getAttribute("userId")%>'
 var obj1;
 var name="";
 for (i=0;i<obj.length;i++){
 obj1=obj[i].right;
 name=obj[i].name;
 alert(name);
 }
这样是可以获取到的,但我没有用EXTJS,我怎么转换,谢谢!

------解决方案--------------------
var obj=
{
"FUNlist":
[
{"FunBh":1,"Url":"www.sohu.com","Xh":1,"ID":"f3994af5-36be39e3-0136-be39ee7e-0001","F_FUNBh":0,"FunName":"学习计划"}
],
"POFlist":
[
{"ORER_BH":1,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":1,"ID":"f3994ab0-36c88bc8-0136-c88bd15e-0001"}, {"ORER_BH":2,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":2,"ID":"f3994ab0-36c88bc8-0136-c88bd19d-0002"}, {"ORER_BH":3,"PART_ID":"f3994af5-36bf0213-0136-bf024183-0001","FUN_ID":"f3994af5-36be39e3-0136-be39ee7e-0001","Xh":3,"ID":"f3994ab0-36c88bc8-0136-c88bd19d-0003"}
]
};
alert((obj.FUNlist)[0].Url);//www.sohu.com
alert((obj.POFlist)[1].ID);//f3994ab0-36c88bc8-0136-c88bd19d-0002
------解决方案--------------------
JScript code
var data=eval("字符串");

------解决方案--------------------
+1
探讨
JScript code
var data=eval("字符串");

------解决方案--------------------
JScript code

            var str = '{"a":"123"}';
            alert(str.a);
            str = eval('('+str+')');
            alert(str.a);