{
"APPLICATION_DETAIL":[
{
"Application1":"",
"Application2":"",
"status":{
"Application1":"Active",
"Application2":"Inactive"
},
"modifiedBy":"a123453"
},
{
"Application1":"",
"Application2":"W",
"status":{
"Application1":"Inactive",
"Application2":"Inactive"
},
"modifiedBy":"a123456"
}
]
}
在上面的JSON对象中,我试图检查两个应用程序的状态是否都处于非活动状态,如果是,我需要删除该对象,我现在正面临挑战甚至读取状态值,状态列表也是动态的它可以是一个值或多个值,任何帮助将不胜感激
答案 0 :(得分:1)
以下是查找所有非活动应用程序索引的代码段:
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);
&#13;
答案 1 :(得分:0)
首先,我将打印您的申请状态:
复制此代码并在浏览器控制台
中运行
的
的void readResource(InputStream source) throws IOException {
BufferedReader stream = null;
try {
stream = new BufferedReader(new InputStreamReader(source));
while (true) {
String line = stream.readLine();
if(line == null) {
break;
}
//process line
System.out.println(line)
}
} finally {
closeQuiet(stream);
}
}
static void closeQuiet(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ignore) {
}
}
}
的
现在您可以在其中添加 if 条件并执行操作