我有以下控制台日志:
[{"$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);
我想输出诸如supporters = {Editor,SupporterA,..};
当我执行console.log(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\".....}]
答案 0 :(得分:1)
您可以使用map
:
const 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":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}]
console.log(data.map(item => item.Name));
答案 1 :(得分:0)
您是否尝试过这种方式
var json = [{"$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 required = {};
for (var i = 0; i < json.length; i++) {
required[i] = json[i].Name;
}
console.log(required)