motools json操作
申屠浩歌
2023-12-01
一、JSON格式:
{
"metadata": [
{"id": "ACTID", "name": "日志ID", "isQuery": "1", "isShow": "0"
},
{ "id": "LOGSOURCE", "name": "日志来源", "isQuery": "0", "isShow": "1"
},
{"id": "LOGLEVEL", "name": "日志级别", "isQuery": "0", "isShow": "1"
},
{ "id": "LOGPRIORITY", "name": "日志优先级","isQuery": "0", "isShow": "1"
},
{"id": "USERID", "name": "用户ID", "isQuery": "0","isShow": "1"
},
{"id": "USERNAME", "name": "用户", "isQuery": "0", "isShow": "1"
},
{ "id": "USERAC", "name": "源账号", "isQuery": "0", "isShow": "1"
},
{"id": "USERIP","name": "源IP","isQuery": "0", "isShow": "1"
},
{"id": "GROUPID", "name": "部门ID", "isQuery": "0", "isShow": "0"
},
{"id": "GROUPNAME", "name": "部门","isQuery": "0", "isShow": "1"
},
{"id": "OPERTIME", "name": "操作时间","isQuery": "0", "isShow": "1"
},
{"id": "OPERTIMEYEAR", "name": "年", "isQuery": "0", "isShow": "1"
}
],
"rows": [
{
"OPERTIMEYEAR": "2016",
"USERAC": "lujunqi",
"GROUPID": "",
"OPERSTATE": "1",
"RESOURCETYPE": "Res-Host",
"USERIP": "132.230.108.109",
"GROUPNAME": "",
"OPERTIME": "2016-06-01 00:00:04.000"
},
{
"OPERTIMEYEAR": "2016",
"USERAC": "seven",
"GROUPID": "368009",
"OPERSTATE": "1",
"RESOURCETYPE": "Res-Host",
"USERIP": "192.168.2.123",
"GROUPNAME": "江西省通信产业服务有限公司(实业公司)",
"OPERTIME": "2016-08-31 13:14:21.000"
}
]
}
二、获取json对象
var jsonResult = JSON.decode('(' + json内容+ ')');
三、解析内容
var metadates = jsonResult.metadata;
for (var i = 0; i < metadates.length; i++) {
fname = metadates[i].name;
isShow = metadates[i].isShow;
}
var rows = jsonResult.rows;
for (var i = 0; i < rows.length; i++) {
row = rows[i];
for (var j = 0; j < metadates .length; j++) {
//获取rows字段值
row[metadata[j].id];
}
}