javascript - How can I convert arraybuffer to json? - Stack Overflow

I want to make a chrome-extension. I need to get the request payload and fetch it. I get the data for r

I want to make a chrome-extension. I need to get the request payload and fetch it. I get the data for requesting like this:

ArrayBuffer(439) {}
[[Int8Array]]: Int8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
[[Uint8Array]]: Uint8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
byteLength: (...)

ArrayBuffer(439) {}
[[Int8Array]]: Int8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
[[Uint8Array]]: Uint8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
byteLength: (...)

What I want is just like this:

{"crawlerInfo":"0anAfxnUgyloq9TVwy6uXXuUPvEOtPJucqE4kaTfd010JVz_MuvWcojytMpfFvK0r4brEP0S6F3DRlnehTr9P0898aJtexul-uF0C5m3hOnyq7OEa0duEcDkFmAIwXcD2jYb3PlyOkzLdKKIESlCBOSn5LoEaRY9GZsFD1VPcsmwZPlEbgPxVNSfsUSzgG4Z26TCbHmAC0mou1CCKAm1UVT15UQX3tFp-tuYbGfT-k4C_cJGLxqZYh-SCARNN9ulH2lLkDjdV-p2wg-1fi3QijKwDXsSC_pfb_iKJPQY6QpBfz1WsayTmTUeCGyajiG3z_PpGvv3sdvzqO9Sr82yZ1T62QXefVCxZZkeqSLv6NIE95QD7ReFsiBfGsKyOkTwDkY1bAb-8Ei18uGlVbnKVicIgN66LORYLrZIj16"}

I want to make a chrome-extension. I need to get the request payload and fetch it. I get the data for requesting like this:

ArrayBuffer(439) {}
[[Int8Array]]: Int8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
[[Uint8Array]]: Uint8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
byteLength: (...)

ArrayBuffer(439) {}
[[Int8Array]]: Int8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
[[Uint8Array]]: Uint8Array(439) [123, 34, 99, 114, 97, 119, 108, 101, 114, 73, 110, 102, 111, 34, 58, 34, 48, 97, 110, 65, 102, 120, 110, 100, 103, 79, 71, 111, 89, 57, 69, 82, 71, 71, 115, 80, 104, 67, 68, 86, 50, 100, 114, 118, 116, 113, 102, 68, 86, 51, 76, 66, 113, 121, 102, 84, 69, 100, 105, 115, 115, 79, 80, 68, 120, 122, 81, 56, 95, 101, 106, 89, 89, 106, 68, 70, 110, 73, 65, 82, 117, 82, 99, 111, 119, 114, 67, 88, 114, 97, 109, 101, 45, 57, 69, 50, 111, 52, 109, 54, …]
byteLength: (...)

What I want is just like this:

{"crawlerInfo":"0anAfxnUgyloq9TVwy6uXXuUPvEOtPJucqE4kaTfd010JVz_MuvWcojytMpfFvK0r4brEP0S6F3DRlnehTr9P0898aJtexul-uF0C5m3hOnyq7OEa0duEcDkFmAIwXcD2jYb3PlyOkzLdKKIESlCBOSn5LoEaRY9GZsFD1VPcsmwZPlEbgPxVNSfsUSzgG4Z26TCbHmAC0mou1CCKAm1UVT15UQX3tFp-tuYbGfT-k4C_cJGLxqZYh-SCARNN9ulH2lLkDjdV-p2wg-1fi3QijKwDXsSC_pfb_iKJPQY6QpBfz1WsayTmTUeCGyajiG3z_PpGvv3sdvzqO9Sr82yZ1T62QXefVCxZZkeqSLv6NIE95QD7ReFsiBfGsKyOkTwDkY1bAb-8Ei18uGlVbnKVicIgN66LORYLrZIj16"}

Share Improve this question edited Nov 9, 2019 at 5:58 NTR 1,3552 gold badges16 silver badges26 bronze badges asked Nov 9, 2019 at 3:58 天气君天气君 973 silver badges9 bronze badges 1
  • 1 Convert it into a string first then use JSON.parse. – woxxom Commented Nov 9, 2019 at 4:06
Add a ment  | 

1 Answer 1

Reset to default 4

As @wOxxOm said, convert it into a string and then parse it.

Note: This will not work for IE (and possibly Edge as well).

// Obviosuly replace this with whatever your array buffer is
const arrayBuffer = new TextEncoder().encode(JSON.stringify({crawlerInfo: "crawler info"}))

const json = JSON.parse(new TextDecoder().decode(arrayBuffer))
console.log(json)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745190823a4615854.html

相关推荐

  • javascript - How can I convert arraybuffer to json? - Stack Overflow

    I want to make a chrome-extension. I need to get the request payload and fetch it. I get the data for r

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信