gpt4 book ai didi

javascript - 使用 javascript/Angular 读取 JSONObjects 中的 JSONOBjects

转载 作者:行者123 更新时间:2023-12-03 10:05:19 24 4
gpt4 key购买 nike

{  
"APPLICATION_DETAIL":[
{
"Application1":"",
"Application2":"",
"status":{
"Application1":"Active",
"Application2":"Inactive"
},
"modifiedBy":"a123453"
},
{
"Application1":"",
"Application2":"W",
"status":{
"Application1":"Inactive",
"Application2":"Inactive"
},
"modifiedBy":"a123456"
}
]
}

在上面的 JSON 对象中,我试图检查两个应用程序的状态是否都处于非事件状态,如果是,我需要删除该对象,我现在面临着读取状态值的挑战,而且状态列表是动态的它可以是一个值或多个值任何帮助将不胜感激

最佳答案

以下是查找所有非事件应用程序索引的代码片段:

var applications = {  
"APPLICATION_DETAIL":[
{
"Application1":"",
"Application2":"",
"status":{
"Application1":"Active",
"Application2":"Inactive"
},
"modifiedBy":"a123453"
},
{
"Application1":"",
"Application2":"W",
"status":{
"Application1":"Inactive",
"Application2":"Inactive"
},
"modifiedBy":"a123456"
}
]
}

applications = applications.APPLICATION_DETAIL;
var applicationsNumber = applications.length;
var objectsToRemove = [];

for(var appIndex = 0; appIndex < applicationsNumber; appIndex++) {
var application = applications[appIndex];
var isActive = false;;

var statuses = Object.keys(application.status);
var statusesNumner = statuses.length;

for(var statusIndex = 0; statusIndex < statusesNumner; statusIndex++) {
if(application.status[statuses[statusIndex]] === 'Active') {
isActive = true;
}
}

if(!isActive) {
objectsToRemove.unshift(appIndex);
}
}

console.log(objectsToRemove);

var removeObjectsNumber = objectsToRemove;
for(var removeIndex = 0; removeIndex < removeObjectsNumber; removeIndex++) {
applications = applications.splice(removeIndex, 1);
}

console.log(applications);

关于javascript - 使用 javascript/Angular 读取 JSONObjects 中的 JSONOBjects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com