Ho un oggetto JSON e lo sto convertendo in un Buffere sto eseguendo un processo qui. Successivamente voglio convertire gli stessi dati del buffer per convertirli in un oggetto JSON valido.
Sto lavorando su Node V6.9.1
Di seguito è riportato il codice che ho provato ma ricevo [object object]quando converto di nuovo in JSON e non riesco ad aprire questo oggetto.
var obj = {
key:'value',
key:'value',
key:'value',
key:'value',
key:'value'
}
var buf = new Buffer.from(obj.toString());
console.log('Real Buffer ' + buf); //This prints --> Real Buffer <Buffer 5b 6f 62 6a 65 63 74>
var temp = buf.toString();
console.log('Buffer to String ' + buf); //This prints --> Buffer to String [object Object]
Quindi ho provato a stampare l'intero oggetto usando il modo Inspect
console.log('Full temp ' + require('util').inspect(buf, { depth: null })); //This prints --> '[object object]' [not printing the obj like declared above]
Se provo a leggerlo come un array
console.log(buf[0]); // This prints --> [
Ho provato anche ad analizzarlo SyntaxError: Unexpected token o in JSON at position 2
Ho bisogno di vederlo come un oggetto reale come ho creato (intendo come dichiarato sopra).
Per favore aiuto..
({"id":"value"}).toString() === '[object Object]' //true