I have made an loop to convert my two dimensional array into an json string. My array (called columns):
[["Application1", "11106.serpkpoe.com", "11109.example.com", "11102.exampleserver.com", "11105.exampleserver.com" "Database, AFPUOR(KNAJKLD)", "Database, UOQZRNJ(LKUJD)" ],
["Application2", "44407.blabla23.com", "11106.exampleserver.com", "11104.exampleserver.com", "Database, POJPR (OIUOLWA) ", "Database, UIAHSD (JJJQEP)" ],...]
I wrote this code to convert the array to json string like this:
for (var i = 0; i < columns.length; i++) {
data[columns[i][0]] = {
Server: [],
Datenbank: []
};
console.log(columns[i][0]);
console.log("1")
for (var j = 1; i < columns[i].length; j++) {
console.log(columns[i][j]);
if (typeof columns[i][j] == 'undefined'){
console.log("----------------undefined break")
break;
}
if (columns[i][j].match("Datenbank")) {
data[columns[i][0]]['Datenbank'].push(columns[i][j]);
console.log("----------------Datenbank gefunden")
} else {
data[columns[i][0]]['Server'].push(columns[i][j]);
console.log("----------------Server gefunden")
}
}
}
The code executes it very well at first but after some columns it just stops and doesnt output values anymore.
it looks like this then:
{
"Application1":{
"Server":[
"Exampleserver1",
"Exampleserver2",
"Exampleserver3",
"Exampleserver4",
"Exampleserver5",
"Exampleserver6",
"Exampleserver7",
"Exampleserver8",
"Exampleserver9",
"Exampleserver10",
],
"Datenbank":[
]
},
"Application2":{
"Server":[
"ExampleserverXYZ12",
"ExampleserverASB22",
"ExampleserverACS32",
"ExampleserverABC42",
"ExampleserverKLJ52",
"ExampleserverPOI62",
"ExampleserverKLJ72",
"ExampleserverTZU82",
"ExampleserverUOI92",
"ExampleserverIL102",
],
"Datenbank":[
]
},
This goes on but for some reason after a few objects it doesnt write the data anymore and then it looks like this:
"Application2":{
"Server":[
"",
"Datenbank":[
]
},
But in the array there is information and I have no idea why it doesnt push them into the json object?
Thank you for your help :)
Aucun commentaire:
Enregistrer un commentaire