Comments (11)
Sorry, it also doesn't seem to work.
require 'faraday'
require 'crack/json'
response = Faraday.get('https://api.vkontakte.ru/method/groups.getById?gids=23201%2C23202%2C23203&fields=country%2Ccity')
Crack::JSON.parse(response.body)
# => Psych::SyntaxError: (<unknown>): control characters are not allowed at line 1 column 1
Or am I doing something wrong?
from vkontakte_api.
this works for me:
# gem list --local
# crack 0.3.1
# faraday 0.8.1
require 'faraday'
require 'crack/json'
require 'openssl/ssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
response = Faraday.get('https://api.vkontakte.ru/method/groups.getById?gids=23201%2C23202%2C23203&fields=country%2Ccity')
p Crack::JSON.parse(response.body)
from vkontakte_api.
I realize, that the problem is because of YAML impelementation.
If you noted in sources - 'crack/json' - just convert json to yaml format and then parse yaml.
We need to find right yaml parser )
from vkontakte_api.
I'm afraid it creates more questions than answers.
- How to make
crack
use some YAML parser instead ofpsych
shipped with MRI 1.9? - How to allow people to use
oj
for production (to go fast) andcrack
for development (to use windows for some reason) without depending on them both in gemspec? I really don't like the idea to make someone manually install other gems forvkontakte_api
to work. It would be ok to have a default slow option working everywhere and a fast option installed separately, but crack doesn't work correctly on 1.9 because of the aforementioned YAML problems. - Parsing JSON with
crack
requires a separate faraday middleware. I wrote one foroj
and it was dead simple, but still.
I personally think the best solution would be to report a bug about installing on windows to oj
developers.
from vkontakte_api.
I agree with you. I'm on 1.8.7 now.
In my vision - the best solution was - have in vkontakte_api inner json parser - slow but plain ruby,
and make check for fast gem installed - and use it for fast parse.
There is plain ruby json parsers, and OJ - will not support win32 I think, and they will be right.
What is the problem of VK's json? Bytes in String? f.e. %01 - if it espace to '\001' - plain ruby json parse it ok.
from vkontakte_api.
The problem here is with this symbol: \x03
. You can get the JSON here, but neither browser nor curl won't show the character - you need to get it in irb or pry or by a script.
And this is not the first time I see broken JSON from VKontakte, it is at least the third time.
from vkontakte_api.
BTW, this fix works:
require 'faraday'
require 'json'
require 'openssl/ssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
response = Faraday.get('https://api.vkontakte.ru/method/groups.getById?gids=23201%2C23202%2C23203&fields=country%2Ccity')
body = response.body.gsub(/\003/, '\u0003')
p JSON.parse(body)
from vkontakte_api.
In VK documentations described \001 byte in JSON response, f.e. "Uploading Audio":
In example of JSON response:
{"server": "1234", "audio": "audio%011300", "hash": "2c75c7e511c5ed39e03cec7fae5a143a"}
note: "%01" in "audio" value.
from vkontakte_api.
@7even насколько я понимаю OJ сейчас лучший гем для парсинга JSON.
Но вот на что я наткнулся. Интересные тесты скорости и сравнение с OJ.
https://github.com/msgpack/msgpack-ruby
https://gist.github.com/4371201
from vkontakte_api.
Да, похожее сравнение есть и в README проекта Oj, но msgpack - это все-таки отдельный формат, несовместимый с JSON - а при работе с ВКонтакте API нужно парсить именно JSON.
from vkontakte_api.
@7even ага, понял, я думал они все таки совместимы, ну ok, спасибо за коммент. =)
from vkontakte_api.
Related Issues (20)
- Непонятная ошибка HOT 2
- Proxy? HOT 1
- Одновременные запросы HOT 1
- cannot load such file -- typhoeus/adapters/faraday HOT 1
- Уберите строгие зависимости гемов HOT 4
- Как посылать сообщения в сообщества? HOT 3
- Rails 5 HOT 3
- Ограничение запросов в секунду HOT 1
- Working with VK stored procedures HOT 3
- Deprecation warning HOT 9
- Hashie::Mash#count Warning HOT 1
- Возвращаемые значения в методе wall.get HOT 1
- Поведение groups.get в test и development environment HOT 2
- :facepalm: HOT 1
- Версия API стала обязательной на вконтакте HOT 6
- Проблема с зависисмотями HOT 5
- Жив ли проект?
- id33266175 HOT 1
- vzl
- 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vkontakte_api.