js解析json读取List中的实体对象示例

JavaScript014

js解析json读取List中的实体对象示例,第1张

1、由后台action

传给前台是需要将map

转成json格式

复制代码

代码如下:

Map<String,

List>

resultMap;

JSONObject

json

=

JSONObject.fromObject(resultMap)

message

=

json.toString()

List中存放多个student对象

2、前台js

中先将结果json串转成对象

复制代码

代码如下:

var

obj

=

eval("("+data+")")

3、遍历取list

中的对象

复制代码

代码如下:

for(var

key

in

obj){

//第一层循环取到各个list

var

List

=

obj[key]

for(var

student

in

List){

//第二层循环取list中的对象

alert(List[student

].id)

alert(List[student

].name)

}

}

business.ResultType = Ext.extend(Ext.form.ComboBox, {

editable: false,

typeAhead: true,

mode: 'local',

readonly: true,

triggerAction: 'all',

selectOnFocus: true,

plugins: new Ext.ux.plugin.TriggerfieldTooltip(),

tooltip: {

title: '结果类型',

text: '请选择结果类型'

},

valueField: 'ID',

displayField: 'NAME',

initComponent: function() {

this.store = new Ext.data.SimpleStore({

fields: ['ID', 'NAME'],

data: [

['10', '1],

['20', '2'],

['30', '源'],

['40', '访'],

['50', '向'],

['60', '已']

]

})

business.ResultType.superclass.initComponent.call(this)

}

})