2016-08-08 18 views
-1

Der Inhalt meiner JSON-Datei ist: Dies ist meine retails.json Datei.Aktiv verkauft ist meine Datenbank.i konvertiert diese JSON-Datei von SQL-Datenbank.so in diesem JSON Datei, möchte ich eine Person Informationen mit einer einzigen ID löschen.Wie kann ich tun? Ich benutze node.js und express.So löschen Sie eine Info mit ID aus JSON-basierten Daten

{ 
"categories" : [ 
{ 
"dept_id" : "123", 
"category_name" : "database", 
"category_discription" : "list of database", 
"current time" : "2016-07-21 06:27:17", 
"id" : "1" 
}, 
{ 
"dept_id" : "1234", 
"category_name" : "debugging", 
"category_discription" : "program debugger", 
"current time" : "2016-07-21 06:32:24", 
"id": "2" 
}, 
{ 
"dept_id" : "12345", 
"category_name" : "system analyzer", 
"category_discription" : null, 
"current time" : "2016-07-21 06:33:23", 
"id" : "3" 
} 
], 
"departments" : [ 
{ 
"name" : "manpreet singh", 
"address_info" : "qadian", 
"current time" : null, 
"id" : "1" 
}, 
{ 
"name" : "tushal gupta", 
"address_info" : "amritsar", 
"current time" : "2016-07-21 06:10:14", 
"id" : "2" 
}, 
{ 
"name" : "haroop singh", 
"address_info" : "amritsar", 
"current time" : "2016-07-21 06:11:12", 
"id" : "3" 
} 
], 

"digital_marketing" : [ 
{ 
"dept_id" : "123", 
"phone" : "99889988", 
"mobile" : null, 
"email" : "[email protected]", 
"web" : null, 
"facebook" : null, 
"twitter" : null, 
"linkedin" : null, 
"current time" : "2016-07-21 06:10:16", 
"id" : "1" 
}, 
{ 
"dept_id" : "1234", 
"phone" : "998899888", 
"mobile" : null, 
"email" : null, 
"web" : null, 
"facebook" : "[email protected]", 
"twitter" : "tushalgupta", 
"linkedin" : null, 
"current time" : "2016-07-21 06:30:19", 
"id" : "2" 
}, 
{ 
"dept_id" : "12345", 
"phone" : "99889877", 
"mobile" : null, 
"email" : "[email protected]", 
"web" : null, 
"facebook":"[email protected]", 
"twitter" : null, 
"linkedin" : null, 
"current time" : "2016-07-21 06:30:13", 
"id" : "3" 
} 
] 
} 

ich dies mit einer ID zu löschen, aber nicht funktioniert:

var id = 2; 
app.get('/deleteUser', function (req, res) { 
// First read existing users. 
fs.readFile(__dirname + "/" + "retails.json", 'utf8', function (err, data) {  
data = JSON.parse(data);  
delete data["categories" + 2];  
    console.log(data); 
    res.end(JSON.stringify(data)); 
    }); 
}); 
+0

Es ist nicht klar, was Sie hier tun wollen. Sie haben den Inhalt einer JSON-Datei, die nichts enthält, in 'Benutzer' eingefügt - was löschen Sie dann? Was ist der Inhalt von 'users.json'? – ishmaelMakitla

+0

Entschuldigung dafür. Ich bearbeite die Frage –

Antwort

0
for (var prop in jsonObj.categories){ 
    delete jsonObj.categories[prop].id; 
} 

ähnlich für digital_marketing usw. jsonObj die Daten in Ihrem Fall ist ..

+0

wo dies zu schreiben ?? nach was? –

+0

Fehler erhalten Fehler: Modul 'jsonObj' nicht gefunden –

+0

Ihre Antwort löscht nur eine ID.aber ich möchte eine Information mit einer einzigen ID löschen. –