“Convertir le tampon en chaîne” Réponses codées

tampon à la chaîne

Your code is working. The buffer you have is actually the string "[object Object]".

let b = Buffer.from('[object Object]', 'utf8')
console.log(JSON.stringify(b))
// {"type":"Buffer","data":[91,111,98,106,101,99,116,32,79,98,106,101,99,116,93]}

console.log(b.toString('utf8'))
// [Object object]
The problem you need to figure out is why is a buffer with that string being sent. It seems like the sender of the buffer needs to call stringify or otherwise serialize the object before sending it. Then you can turn it back to a string with toString() and use JSON.parse() on the string.
Santino

Convertir le tampon en chaîne

// example buffer:

const myBuffer = <Buffer 65 80 4a 30 65 56 41 63 4f 69 4a 4b 56 31 51 69 4c 43 4a 68 62 47 63 69 4f 69 4a 49 55 7a 49 31 4e 69 4a 39 2e 65 79 4a 68 63 47 6c 66 61 32 56 35 49 ... 185 more bytes>
  
const this_is_a_string = myBuffer.toString();
Chrysler

Réponses similaires à “Convertir le tampon en chaîne”

Questions similaires à “Convertir le tampon en chaîne”

Plus de réponses similaires à “Convertir le tampon en chaîne” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code