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

Ext.Ajax.request() 中 json取值问题! - Web 开发 / Ajax
function userQueryAjax(){
  Ext.Ajax.request({
  method: 'post',
  url : 'className/methodName.json',
  success: function(temp){
  showFunc(temp.responseText);
  },
  failure: XXX
});
}

function showFunc(json){
  alert(json); //这里会弹出后台取出的json值 比如 {userList:[{userid:"001",userName:"bbb"}]}类似的值
  alert(json.userList); //按照上面的值 这样应该弹出 [{userid:"001,userName:"bbb"}] 但是弹出的对
  话框却说 undefined  
}

前台是 JSP 后台是 JAVA 
请高手帮忙解决下 因为已经晚了 要停电了。。如果有回帖明天再来结贴 谢谢

------解决方案--------------------
返回的是字符串,还需要进行反序列化
比如

showFunc(eval(temp.responseText));
------解决方案--------------------
引入JSON.js

showFunc(Ext.util.JSON.decode(temp.responseText));
------解决方案--------------------
showFunc(temp.responseText);

=》

showFunc(eval(temp.responseText));
------解决方案--------------------
此时的json是字符串,不是对象,所以要进行反序列化成对象,var obj=Ext.decode(json);再调用obj.userList!