“converter buffer em string” Respostas de código

buffer para string

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

converter buffer em string

// 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

Respostas semelhantes a “converter buffer em string”

Perguntas semelhantes a “converter buffer em string”

Mais respostas relacionadas para “converter buffer em string” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código