关于ext读取json字符串中的某个属性的值

来源:互联网 发布:中医宝典大全软件 编辑:程序博客网 时间:2024/04/29 09:11
今天在做项目的时候 需要用Ajax去得到后台一个方法的返回值,按理说后台正常应该返回一个Object类型的数据,但是因为那个方法同时被别的功能所使用,所以只能在前台进行调整
Ext.Ajax.request({url: 'KnowledgeAction!treeShow.action',success: function(response,opts) {var message =response.responseTex;alert(message);                                                                        },failure: function(response,opts) {alert('刷新异常');},     params: {'obj.id':node.attributes.id}   });  

这里 message的结果为 {"info":[{"usertype":"居民用户","missiongrade":"普通"}]}现在我就要取出usertype中的值  如果后台传过来的是Object类型的数据 那么我可以这样

var usertype=message.usertype;  但是现在传过来的是一堆字符串 那么我们需要在这里进行一下处理,让他在前台转换为Object, 代码如下:

Ext.Ajax.request({url: 'KnowledgeAction!treeShow.action',success: function(response,opts) {var message =eval('('+response.responseText+')');alert(message);                                                                 Ext.getCmp("bl").setValue(message.usertype)                                                                 },failure: function(response,opts) {alert('刷新异常');},     params: {'obj.id':node.attributes.id}   }); 

var usertype=message.usertype;  这样处理后,我的message就变为Object类型的数据了  那么就可以取得其中的属性值啦!!!!!

原创粉丝点击