在JavaScript节点环境中将Gzip内容编码响应转换为JSON数据 [英] Turn Gzip Content Encoding Response to JSON Data in JavaScript Node Environment

查看:73
本文介绍了在JavaScript节点环境中将Gzip内容编码响应转换为JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个小型Web应用程序项目,该项目使用ParseHub抓取Web数据并使用d3.js将其显示在我的网站上.但是,根据 ParseHub API ,它们仅以gzip内容编码格式返回JSON数据.我想找到一种将压缩后的内容膨胀为JSON并将其直接输入到d3模型中的方法.我已经尝试过从该站点的线程中找到的poke和JXGcompressor,但是都没有用,不确定是否是因为我使用了错误的它们.请帮我!谢谢!

I'm working on a small web app project that uses ParseHub to scrape web data and display it on my site using d3.js. However, according to ParseHub API, they only return JSON data in gzip content-encoding format. I want to find a way to inflate the compressed content to JSON and feed it directly in my d3 model. I've tried poke and JXGcompressor which I found from threads on this site, but neither worked, not sure if it's because I used them wrong. Please help me! Thank you!

以下是我得到的回复:

{"statusCode":200,"body":"\u001f�\b\b\u0000��V\u0002\u0003tzRbY-385ECKLE7qbgihaY6U\u0000�\\[s��r�+��ڷ�j��umي��9�CjLA\"J �
...
=���|�='�7�k\u0001x)��\n�ʸ\u000b\u00125���B9�D��vf�/��h{����:\u0017[̅A\u0004���$��\u0015���\u001et��ÈVB5����Ь���\u000fh�Nr\u0000\u0000","headers":{"server":"nginx/1.8.0","date":"Wed, 30 Mar 2016 22:54:17 GMT","content-type":"application/json","content-length":"6549","connection":"close","content-encoding":"gzip","last-modified":...}

推荐答案

找到了一个超级简单的答案,这挽救了我的生命!!!

Found a super easy answer, this saved my life!!!!

Ryan Knell在此处https://https://stackoverflow.com/questions/8880741/stackoverflow.com/questions/8880741/node-js-easy-http-requests-with-gzip-deflate-compression

Ryan Knell posted this answer here:https://stackoverflow.com/questions/8880741/node-js-easy-http-requests-with-gzip-deflate-compression

我需要做的就是在请求中包含"gzip:true",因为请求已支持它: https://github.com/request/request

All I needed was to include "gzip: true" in my request, because request already supports it:https://github.com/request/request

这篇关于在JavaScript节点环境中将Gzip内容编码响应转换为JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆