首页 新闻 搜索 专区 学院

怎么用js遍历jsonArray的值?

0
悬赏园豆:10 [已解决问题] 解决于 2018-07-18 17:11

function recordeInfo(info) {
console.log(info);
var data = eval(info.FileList);

console.log(data);

 

 

js
等不到天亮的主页 等不到天亮 | 初学一级 | 园豆:23
提问于:2018-07-18 14:33
< >
分享
最佳答案
0

用js 解析json字符串

然后在循环 这个json 数组里面的 想要的东西就行

 

https://www.cnblogs.com/jtlgb/p/6137915.html

收获园豆:10
竜咚咚 | 小虾三级 |园豆:775 | 2018-07-18 15:04

我这样试过,为什么也还是取不出来,纳闷。。。

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 15:06

至少要定位到FileList下吧

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 15:07

@等不到天亮: 把你这个json 给我   我给你弄一下

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 15:12

@竜咚咚: 

回放成功!录像搜索成功:{"FileList":[{"EndTime":"2018-07-16 10:13:11","StartTime":"2018-07-16 10:12:13"},{"EndTime":"2018-07-16 10:27:58","StartTime":"2018-07-16 10:27:03"},{"EndTime":"2018-07-16 10:35:53","StartTime":"2018-07-16 10:35:00"},{"EndTime":"2018-07-16 10:55:46","StartTime":"2018-07-16 10:54:54"},{"EndTime":"2018-07-16 11:14:10","StartTime":"2018-07-16 11:13:16"},{"EndTime":"2018-07-16 11:19:45","StartTime":"2018-07-16 11:18:49"},{"EndTime":"2018-07-16 12:30:45","StartTime":"2018-07-16 12:29:54"},{"EndTime":"2018-07-16 15:10:50","StartTime":"2018-07-16 15:09:37"},{"EndTime":"2018-07-16 15:51:52","StartTime":"2018-07-16 15:50:19"},{"EndTime":"2018-07-16 15:53:25","StartTime":"2018-07-16 15:52:21"},{"EndTime":"2018-07-16 19:15:54","StartTime":"2018-07-16 19:15:02"},{"EndTime":"2018-07-16 19:27:48","StartTime":"2018-07-16 19:26:16"},{"EndTime":"2018-07-16 19:29:07","StartTime":"2018-07-16 19:28:18"},{"EndTime":"2018-07-16 19:30:25","StartTime":"2018-07-16 19:29:34"},{"EndTime":"2018-07-16 19:32:56","StartTime":"2018-07-16 19:32:03"},{"EndTime":"2018-07-17 05:27:55","StartTime":"2018-07-17 05:27:02"},{"EndTime":"2018-07-17 05:33:42","StartTime":"2018-07-17 05:32:49"},{"EndTime":"2018-07-17 05:39:01","StartTime":"2018-07-17 05:38:04"},{"EndTime":"2018-07-17 08:11:06","StartTime":"2018-07-17 08:10:13"},{"EndTime":"2018-07-17 08:44:02","StartTime":"2018-07-17 08:42:39"},{"EndTime":"2018-07-17 08:46:54","StartTime":"2018-07-17 08:46:03"},{"EndTime":"2018-07-17 09:10:51","StartTime":"2018-07-17 09:10:39"},{"EndTime":"2018-07-17 09:11:33","StartTime":"2018-07-17 09:10:51"},{"EndTime":"2018-07-17 09:22:04","StartTime":"2018-07-17 09:21:09"},{"EndTime":"2018-07-17 09:31:09","StartTime":"2018-07-17 09:30:16"},{"EndTime":"2018-07-17 14:56:51","StartTime":"2018-07-17 14:55:46"},{"EndTime":"2018-07-17 15:39:56","StartTime":"2018-07-17 15:37:40"},{"EndTime":"2018-07-17 15:41:52","StartTime":"2018-07-17 15:40:57"},{"EndTime":"2018-07-17 15:56:22","StartTime":"2018-07-17 15:55:15"},{"EndTime":"2018-07-17 16:00:52","StartTime":"2018-07-17 15:59:59"},{"EndTime":"2018-07-17 17:42:07","StartTime":"2018-07-17 17:41:15"},{"EndTime":"2018-07-17 18:22:51","StartTime":"2018-07-17 18:21:57"},{"EndTime":"2018-07-17 18:27:39","StartTime":"2018-07-17 18:26:46"},{"EndTime":"2018-07-17 19:26:24","StartTime":"2018-07-17 19:24:51"},{"EndTime":"2018-07-17 19:27:37","StartTime":"2018-07-17 19:26:45"},{"EndTime":"2018-07-17 19:28:42","StartTime":"2018-07-17 19:27:51"},{"EndTime":"2018-07-17 19:30:23","StartTime":"2018-07-17 19:29:32"},{"EndTime":"2018-07-17 22:37:42","StartTime":"2018-07-17 22:36:52"},{"EndTime":"2018-07-17 22:39:45","StartTime":"2018-07-17 22:38:17"},{"EndTime":"2018-07-17 22:40:28","StartTime":"2018-07-17 22:39:45"},{"EndTime":"2018-07-17 22:41:44","StartTime":"2018-07-17 22:40:54"},{"EndTime":"2018-07-17 22:45:14","StartTime":"2018-07-17 22:43:59"},{"EndTime":"2018-07-17 22:46:17","StartTime":"2018-07-17 22:45:25"},{"EndTime":"2018-07-17 22:48:25","StartTime":"2018-07-17 22:47:32"},{"EndTime":"2018-07-17 22:54:03","StartTime":"2018-07-17 22:53:12"},{"EndTime":"2018-07-17 22:55:28","StartTime":"2018-07-17 22:54:38"},{"EndTime":"2018-07-17 22:57:37","StartTime":"2018-07-17 22:56:47"},{"EndTime":"2018-07-17 23:07:38","StartTime":"2018-07-17 23:06:48"},{"EndTime":"2018-07-18 02:34:18","StartTime":"2018-07-18 02:33:26"},{"EndTime":"2018-07-18 02:36:01","StartTime":"2018-07-18 02:35:09"},{"EndTime":"2018-07-18 02:37:13","StartTime":"2018-07-18 02:36:24"},{"EndTime":"2018-07-18 02:41:57","StartTime":"2018-07-18 02:41:04"},{"EndTime":"2018-07-18 05:36:04","StartTime":"2018-07-18 05:35:07"},{"EndTime":"2018-07-18 05:39:30","StartTime":"2018-07-18 05:38:30"},{"EndTime":"2018-07-18 05:55:14","StartTime":"2018-07-18 05:54:18"},{"EndTime":"2018-07-18 05:57:00","StartTime":"2018-07-18 05:55:52"},{"EndTime":"2018-07-18 06:01:31","StartTime":"2018-07-18 06:00:29"},{"EndTime":"2018-07-18 06:15:45","StartTime":"2018-07-18 06:14:28"},{"EndTime":"2018-07-18 08:03:57","StartTime":"2018-07-18 08:02:50"},{"EndTime":"2018-07-18 08:06:46","StartTime":"2018-07-18 08:05:01"},{"EndTime":"2018-07-18 08:11:35","StartTime":"2018-07-18 08:10:40"},{"EndTime":"2018-07-18 08:16:04","StartTime":"2018-07-18 08:14:48"},{"EndTime":"2018-07-18 08:21:02","StartTime":"2018-07-18 08:19:45"},{"EndTime":"2018-07-18 08:24:49","StartTime":"2018-07-18 08:21:02"},{"EndTime":"2018-07-18 08:26:39","StartTime":"2018-07-18 08:25:06"},{"EndTime":"2018-07-18 08:30:01","StartTime":"2018-07-18 08:27:56"},{"EndTime":"2018-07-18 08:32:02","StartTime":"2018-07-18 08:30:13"},{"EndTime":"2018-07-18 08:33:21","StartTime":"2018-07-18 08:32:06"},{"EndTime":"2018-07-18 08:40:45","StartTime":"2018-07-18 08:39:56"},{"EndTime":"2018-07-18 08:42:37","StartTime":"2018-07-18 08:41:23"},{"EndTime":"2018-07-18 08:44:28","StartTime":"2018-07-18 08:43:41"},{"EndTime":"2018-07-18 08:58:17","StartTime":"2018-07-18 08:56:47"},{"EndTime":"2018-07-18 09:02:55","StartTime":"2018-07-18 09:02:05"},{"EndTime":"2018-07-18 09:07:37","StartTime":"2018-07-18 09:06:49"},{"EndTime":"2018-07-18 09:08:34","StartTime":"2018-07-18 09:08:04"},{"EndTime":"2018-07-18 09:08:53","StartTime":"2018-07-18 09:08:34"},{"EndTime":"2018-07-18 09:09:42","StartTime":"2018-07-18 09:08:54"},{"EndTime":"2018-07-18 09:18:00","StartTime":"2018-07-18 09:14:17"},{"EndTime":"2018-07-18 09:21:55","StartTime":"2018-07-18 09:19:44"},{"EndTime":"2018-07-18 09:22:42","StartTime":"2018-07-18 09:21:55"},{"EndTime":"2018-07-18 09:23:54","StartTime":"2018-07-18 09:23:01"},{"EndTime":"2018-07-18 09:25:32","StartTime":"2018-07-18 09:23:54"},{"EndTime":"2018-07-18 09:32:59","StartTime":"2018-07-18 09:26:24"},{"EndTime":"2018-07-18 09:33:36","StartTime":"2018-07-18 09:32:59"},{"EndTime":"2018-07-18 09:36:19","StartTime":"2018-07-18 09:35:07"},{"EndTime":"2018-07-18 09:37:42","StartTime":"2018-07-18 09:36:24"},{"EndTime":"2018-07-18 09:42:15","StartTime":"2018-07-18 09:38:57"},{"EndTime":"2018-07-18 09:44:06","StartTime":"2018-07-18 09:43:17"},{"EndTime":"2018-07-18 09:46:13","StartTime":"2018-07-18 09:45:24"},{"EndTime":"2018-07-18 09:47:11","StartTime":"2018-07-18 09:46:23"},{"EndTime":"2018-07-18 09:48:08","StartTime":"2018-07-18 09:47:22"},{"EndTime":"2018-07-18 09:51:12","StartTime":"2018-07-18 09:50:23"},{"EndTime":"2018-07-18 09:52:45","StartTime":"2018-07-18 09:51:25"},{"EndTime":"2018-07-18 09:54:06","StartTime":"2018-07-18 09:53:20"},{"EndTime":"2018-07-18 09:56:34","StartTime":"2018-07-18 09:55:02"},{"EndTime":"2018-07-18 09:57:29","StartTime":"2018-07-18 09:56:40"},{"EndTime":"2018-07-18 10:00:19","StartTime":"2018-07-18 09:57:29"},{"EndTime":"2018-07-18 10:03:27","StartTime":"2018-07-18 10:00:19"},{"EndTime":"2018-07-18 10:04:20","StartTime":"2018-07-18 10:03:27"},{"EndTime":"2018-07-18 10:09:58","StartTime":"2018-07-18 10:06:05"},{"EndTime":"2018-07-18 10:12:03","StartTime":"2018-07-18 10:11:16"},{"EndTime":"2018-07-18 10:13:43","StartTime":"2018-07-18 10:12:06"},{"EndTime":"2018-07-18 10:15:55","StartTime":"2018-07-18 10:14:22"},{"EndTime":"2018-07-18 10:22:06","StartTime":"2018-07-18 10:18:27"},{"EndTime":"2018-07-18 10:24:17","StartTime":"2018-07-18 10:23:29"},{"EndTime":"2018-07-18 10:25:03","StartTime":"2018-07-18 10:24:17"},{"EndTime":"2018-07-18 10:26:49","StartTime":"2018-07-18 10:25:03"},{"EndTime":"2018-07-18 10:28:06","StartTime":"2018-07-18 10:27:11"},{"EndTime":"2018-07-18 10:33:05","StartTime":"2018-07-18 10:30:21"},{"EndTime":"2018-07-18 10:34:50","StartTime":"2018-07-18 10:33:06"},{"EndTime":"2018-07-18 10:35:59","StartTime":"2018-07-18 10:35:10"},{"EndTime":"2018-07-18 10:40:12","StartTime":"2018-07-18 10:39:21"},{"EndTime":"2018-07-18 10:40:55","StartTime":"2018-07-18 10:40:12"},{"EndTime":"2018-07-18 10:44:26","StartTime":"2018-07-18 10:42:41"},{"EndTime":"2018-07-18 10:49:29","StartTime":"2018-07-18 10:44:50"},{"EndTime":"2018-07-18 10:51:18","StartTime":"2018-07-18 10:50:12"},{"EndTime":"2018-07-18 10:52:04","StartTime":"2018-07-18 10:51:25"},{"EndTime":"2018-07-18 10:53:52","StartTime":"2018-07-18 10:52:33"},{"EndTime":"2018-07-18 10:55:22","StartTime":"2018-07-18 10:53:53"},{"EndTime":"2018-07-18 10:59:47","StartTime":"2018-07-18 10:58:22"},{"EndTime":"2018-07-18 11:05:08","StartTime":"2018-07-18 11:04:19"},{"EndTime":"2018-07-18 11:06:49","StartTime":"2018-07-18 11:05:47"},{"EndTime":"2018-07-18 11:11:23","StartTime":"2018-07-18 11:09:22"},{"EndTime":"2018-07-18 11:17:28","StartTime":"2018-07-18 11:16:05"},{"EndTime":"2018-07-18 11:24:21","StartTime":"2018-07-18 11:17:38"},{"EndTime":"2018-07-18 11:26:13","StartTime":"2018-07-18 11:24:21"},{"EndTime":"2018-07-18 11:27:10","StartTime":"2018-07-18 11:26:21"},{"EndTime":"2018-07-18 11:48:29","StartTime":"2018-07-18 11:47:36"},{"EndTime":"2018-07-18 11:50:30","StartTime":"2018-07-18 11:48:29"},{"EndTime":"2018-07-18 11:54:35","StartTime":"2018-07-18 11:53:25"},{"EndTime":"2018-07-18 11:55:34","StartTime":"2018-07-18 11:54:46"},{"EndTime":"2018-07-18 11:58:54","StartTime":"2018-07-18 11:57:28"},{"EndTime":"2018-07-18 12:02:59","StartTime":"2018-07-18 12:02:08"},{"EndTime":"2018-07-18 12:04:27","StartTime":"2018-07-18 12:02:59"},{"EndTime":"2018-07-18 12:08:13","StartTime":"2018-07-18 12:04:27"},{"EndTime":"2018-07-18 12:10:09","StartTime":"2018-07-18 12:08:15"},{"EndTime":"2018-07-18 12:10:52","StartTime":"2018-07-18 12:10:09"},{"EndTime":"2018-07-18 12:13:05","StartTime":"2018-07-18 12:10:52"},{"EndTime":"2018-07-18 12:15:10","StartTime":"2018-07-18 12:13:06"},{"EndTime":"2018-07-18 12:18:13","StartTime":"2018-07-18 12:15:16"},{"EndTime":"2018-07-18 12:23:11","StartTime":"2018-07-18 12:21:39"},{"EndTime":"2018-07-18 12:30:57","StartTime":"2018-07-18 12:23:44"},{"EndTime":"2018-07-18 12:41:24","StartTime":"2018-07-18 12:30:57"},{"EndTime":"2018-07-18 12:43:13","StartTime":"2018-07-18 12:41:53"},{"EndTime":"2018-07-18 12:45:56","StartTime":"2018-07-18 12:43:39"},{"EndTime":"2018-07-18 12:46:41","StartTime":"2018-07-18 12:45:56"},{"EndTime":"2018-07-18 12:47:28","StartTime":"2018-07-18 12:46:41"},{"EndTime":"2018-07-18 12:49:41","StartTime":"2018-07-18 12:48:07"},{"EndTime":"2018-07-18 12:50:20","StartTime":"2018-07-18 12:49:41"},{"EndTime":"2018-07-18 12:53:27","StartTime":"2018-07-18 12:52:13"},{"EndTime":"2018-07-18 12:57:10","StartTime":"2018-07-18 12:53:27"},{"EndTime":"2018-07-18 12:58:25","StartTime":"2018-07-18 12:57:12"},{"EndTime":"2018-07-18 13:01:06","StartTime":"2018-07-18 12:59:58"},{"EndTime":"2018-07-18 13:10:18","StartTime":"2018-07-18 13:01:32"},{"EndTime":"2018-07-18 13:18:25","StartTime":"2018-07-18 13:10:18"},{"EndTime":"2018-07-18 13:21:11","StartTime":"2018-07-18 13:18:46"},{"EndTime":"2018-07-18 13:23:44","StartTime":"2018-07-18 13:22:05"},{"EndTime":"2018-07-18 13:26:22","StartTime":"2018-07-18 13:24:17"},{"EndTime":"2018-07-18 13:27:55","StartTime":"2018-07-18 13:26:22"},{"EndTime":"2018-07-18 13:28:53","StartTime":"2018-07-18 13:27:59"},{"EndTime":"2018-07-18 13:29:20","StartTime":"2018-07-18 13:28:53"},{"EndTime":"2018-07-18 13:31:58","StartTime":"2018-07-18 13:31:05"},{"EndTime":"2018-07-18 13:34:28","StartTime":"2018-07-18 13:33:40"},{"EndTime":"2018-07-18 13:38:50","StartTime":"2018-07-18 13:37:55"},{"EndTime":"2018-07-18 13:39:44","StartTime":"2018-07-18 13:38:52"},{"EndTime":"2018-07-18 13:44:52","StartTime":"2018-07-18 13:40:14"},{"EndTime":"2018-07-18 14:09:45","StartTime":"2018-07-18 14:07:57"}],"FileSize":167}

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 15:14

@竜咚咚: 这个是第三方接口返回的

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 15:15

@等不到天亮: 

var str = "{\"FileList\": [{ \"EndTime\": \"2018-07-16 10:13:11\",\"StartTime\": \"2018-07-16 10:12:13\"}],\"FileSize\": 167}";
var obj = JSON.parse(str);

alert(obj.FileList[0].EndTime);

 

 

这样就可以   你试一下

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 15:40

@竜咚咚: 这个格式怎么拆分的

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:20

@等不到天亮:你请求这个接口  他给你返回了一个json串   你解析他这个串就行 js里用我给你的这个方法就行

 

或者你也可以在后端处理    你现在的疑惑是什么

 

这个json  两个大的节点  FileList 这个节点中是个数组  也是你要的数据

      

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 16:25

@竜咚咚: 

//var data =JSON.stringify(info);
console.log(info);
var obj = JSON.parse(info);
//console.log(data);
for(i = 0; i < obj.length; i++)
{

var endTime = obj.FileList[i].EndTime;
console.log(endTime);
}

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:27

@竜咚咚: baocuo

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:29

@竜咚咚:返回的是这样的格式,filelist前面没有引号

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:31

@等不到天亮: 

var str = { "FileList": [{ "EndTime": "2018-07-16 10:13:11", "StartTime": "2018-07-16 10:12:13" }, { "EndTime": "2018-07-16 10:13:11", "StartTime": "2018-07-16 10:12:13" }], "FileSize": 167 };
var obj = eval(str);

for (i = 0; i < obj.FileList.length; i++) {

var endTime = obj.FileList[i].EndTime;
alert(endTime);
}

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 16:43

@竜咚咚: 谢谢,我知道问题了,找的那个json字段不完整。

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:54

@竜咚咚: 后面就没有

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:55

@等不到天亮: 解决了  就行

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 16:57

@竜咚咚: 是呀,我没仔细看,这个是个坑,我再想想这个字段哪里有返回

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 16:59

@竜咚咚: 你微信号多少呀,我是菜鸟,可不可以问你些问题

等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 17:10

@等不到天亮: 13161064067

竜咚咚 | 园豆:775 (小虾三级) | 2018-07-18 17:43
其他回答(2)
0

for(j = 0; j < data.length; j++)

{

 

var item=data[i].字段;

}

lbx.tom | 园豆:202 (菜鸟二级) | 2018-07-18 14:39

我这样写过,取不出来,undefind

支持(0) 反对(0) 等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 14:41

至少要先把FileList下的数据显示出来,总是取不出来,不知道怎么写了

支持(0) 反对(0) 等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 14:42

@等不到天亮: data[i]["字段名称"]试试。具体的也记不太清了,你可以试试

支持(0) 反对(0) lbx.tom | 园豆:202 (菜鸟二级) | 2018-07-18 15:16

@lbx.tom: 

console.log(info);
//var o = eval(info.FileList);
var data =JSON.stringify(info);
console.log(data);
for(var i in data){
console.log(data[i].StartTime);
}

那个试过了,不行

支持(0) 反对(0) 等不到天亮 | 园豆:23 (初学一级) | 2018-07-18 15:20
0

for( var i in json ){

  //

}

 

..其实  js真的有jsonArray对象么。。 表示怀疑。。

blurs | 园豆:664 (小虾三级) | 2018-07-18 15:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册