Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Json对象获取数组中的值_Javascript - Fatal编程技术网

Javascript 从Json对象获取数组中的值

Javascript 从Json对象获取数组中的值,javascript,Javascript,我有以下控制台日志: [{"$id":"1","EmailConfirmedDate":null,"InvitedDate":null,"Username":"abc@bcd.de","Email":"abc@bcd.de","RawPasswordValue":"wC90YmqM1+gFdMAvE2ONAg==E+7bIhf7nBoEmLhs0qn2UAmuzD9cq245gi1Nfr6PvXI=","IsApproved":true,**"Name":"Editor"**,"Avatar"

我有以下控制台日志:

 [{"$id":"1","EmailConfirmedDate":null,"InvitedDate":null,"Username":"abc@bcd.de","Email":"abc@bcd.de","RawPasswordValue":"wC90YmqM1+gFdMAvE2ONAg==E+7bIhf7nBoEmLhs0qn2UAmuzD9cq245gi1Nfr6PvXI=","IsApproved":true,**"Name":"Editor"**,"Avatar":null,"TourData":null,"SessionTimeout":60,"StartContentIds":[],"StartMediaIds":[],"Language":"en-US","Groups":[],"Id":1,"Key":"00000001-0000-0000-0000-000000000000","CreateDate":"2018-06-20T09:27:27.517Z","UpdateDate":"2018-06-20T09:35:57.783Z","HasIdentity":true},{"$id":"2","EmailConfirmedDate":null,"InvitedDate":null,"Username":"SupporterA@umbraco.de","Email":"SupporterA@umbraco.de","RawPasswordValue":"cxEu22do6dAg9gtpNI7THQ==FY0RGPHPWMggVUw++pLL5/sVRzU0syuNSCxbus+6LYw=","IsApproved":true,**"Name":"SupporterA"**,"Avatar":null,"TourData":null,"SessionTimeout":60,"StartContentIds":[],"StartMediaIds":[],"Language":"en-US","Groups":[],"Id":2,"Key":"00000002-0000-0000-0000-000000000000","CreateDate":"2018-06-20T11:45:41.257Z","UpdateDate":"2018-06-20T11:46:15.53Z","HasIdentity":true}]

我只想得到数组中的名称。我试了很多,但都不管用

 var suppList = JSON.parse(response.data);

console.log(suppList);
我想输出类似于支持者的东西={Editor,SupporterA,…}

执行console.log(response.data)时:


您可以为此使用
map

const data=[{“$id”:“1”,“EmailConfirmedDate”:null,“InvitedDate”:null,“Username”:abc@bcd.de,“电子邮件”:abc@bcd.de“,“RawPasswordValue”:“wC90YmqM1+gFdMAvE2ONAg==E+7bIhf7nBoEmLhs0qn2UAmuzD9cq245gi1Nfr6PvXI=”,“IsApproved”:true,“Name”:“Editor”,“Avatar”:null,“TourData”:null,“SessionTimeout”:60,“StartContents”:[],“StartMediaIds”:[],“Language”:“en-US”,“Groups”:[],“Id”:1,“Key”:“00000001-0000-0000-0000-000000000000”,“CreateDate”:“2018-06-20T09:27:27.517Z”,“UpdateDate”:“2018-06-20T09:35:57.783Z”,“HasIdentity”:true},{$Id:“2”,“EmailConfirmedDate”:null,“InvitedDate”:null,“用户名”:”SupporterA@umbraco.de,“电子邮件”:SupporterA@umbraco.de,“RawPasswordValue”:cxEu22do6dAg9gtpNI7THQ==FY0RGPHPWMggVUw++pLL5/sVRzU0syuNSCxbus+6LYw=“,“IsApproved”:true,“Name”:“SupporterA”,“Avatar”:null,“TourData”:null,“SessionTimeout”:60,“StartContents”:[],“Language”:“en-US”,“Group”:[],“Id”:2,“Key”:“00000002-0000-0000-000000000000”,“CreateDate”:“2018-06-20T11:45:41.257Z”,“UpdateDate”:”:”2018-06-20T11:46:15.53Z,“hasidenty”:true}]

console.log(data.map(item=>item.Name));
您是否尝试过这种方法

var json=[{“$id”:“1”,“EmailConfirmedDate”:null,“InvitedDate”:null,“Username”:abc@bcd.de,“电子邮件”:abc@bcd.de“,“RawPasswordValue”:“wC90YmqM1+gFdMAvE2ONAg==E+7bIhf7nBoEmLhs0qn2UAmuzD9cq245gi1Nfr6PvXI=”,“IsApproved”:true,“Name”:“Editor”,“Avatar”:null,“TourData”:null,“SessionTimeout”:60,“StartContents”:[],“StartMediaIds”:[],“Language”:”在美国,“组”:[],“Id”:1,“键”:“00000001-0000-0000-0000-000000000000”,“创建日期”:“2018-06-20T09:27:27.517Z”,“更新日期”:“2018-06-20T09:35:57.783Z”,“HasIdentity”:true},{“$Id”:“2”,“EmailConfirmedDate”:null,“InvitedDate”:null,“用户名”:”SupporterA@umbraco.de,“电子邮件”:SupporterA@umbraco.de,“RawPasswordValue”:cxEu22do6dAg9gtpNI7THQ==FY0RGPHPWMggVUw++pLL5/sVRzU0syuNSCxbus+6LYw=“,“IsApproved”:true,“Name”:“SupporterA”,“Avatar”:null,“TourData”:null,“SessionTimeout”:60,“StartContents”:[],“Language”:“en-US”,“Group”:[],“Id”:2,“Key”:“00000002-0000-0000-000000000000”,“CreateDate”:“2018-06-20T11:45:41.257Z”,“UpdateDate”:”:”2018-06-20T11:46:15.53Z,“hasidenty”:true});
var required={};
for(var i=0;iconsole.log(必选)
“我尝试了很多,但都没有效果”。您尝试了什么?从中得到的输出是什么?您到底在寻找什么以及为什么要实现它?是否只寻找要放置到数组中的键?suppList[0]。Name,suppList.Name,suppList['Name']等,并且始终输出未确定。不是键,而是来自键的值。这是我尝试此操作时得到的结果:{0:undefined,1:undefined,2:undefined,3:undefined,4:undefined,5:undefined,6:undefined,7:undefined,8:undefined,9:undefined,10:undefined,11:undefined,12:undefined,13:undefined,14:undefined,15….你试过我在这里发布的
运行代码片段吗?我认为你提供的数据有问题我得到一个错误:TypeError:suppList.map不是一个你不需要的函数
suppList
。只要使用我发布的代码就行了。这是我尝试的结果,出现了相同的错误:const data=JSON.parse(response.data);console.log(data.map(item=>item.Name));听起来像是JSON.parse没有生成数组。什么是
typeof response.data
typeof JSON.parse(response.data)
?你能在问题中的JSON.parse之前发布确切的
response.data
[{\"$id\":\"1\",\"EmailConfirmedDate\":null,\"InvitedDate\":null,\"Username\":\"abc@bcd.de\",\"Email\":\"abc@bcd.de\",\"RawPasswordValue\":\"wC90YmqM1+gFdMAvE2ONAg==E+7bIhf7nBoEmLhs0qn2UAmuzD9cq245gi1Nfr6PvXI=\",\"IsApproved\":true,\"Name\":\"Editor\",\"Avatar\".....}]