Created
January 26, 2018 10:30
-
-
Save nuclearglow/ab251744db0ebddd504eea28153eb279 to your computer and use it in GitHub Desktop.
ArrayBuffer <-> JSON <-> ArrayBuffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// array buffer to JSON | |
const dataString JSON.stringify(Array.from(new Uint8Array(arrayBuffer))); | |
// send around | |
// JSON to ArrayBuffer | |
new Uint8Array(JSON.parse(dataString)).buffer |
Hey there! I think your dataString is not working properlly
I tried like below and it worked
console.log(JSON.parse(String.fromCharCode.apply(null, new Uint8Array(data))));
Thanks, working good.
Thanks very useful :)
So many blog posts about this, and this answer is the best. 👍
const enc = new TextDecoder("utf-8");
const data =new Uint8Array(res)
console.log(JSON.parse(enc.decode(data)))
This was extremely helpful to me! This is truly an outstanding answer! Thank you, nuclearglow - you're a lifesaver!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there! I think your dataString is not working properlly
I tried like below and it worked