Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OJ JSON Parsing Error #17

Closed
targence opened this issue Mar 5, 2013 · 5 comments
Closed

OJ JSON Parsing Error #17

targence opened this issue Mar 5, 2013 · 5 comments

Comments

@targence
Copy link
Contributor

targence commented Mar 5, 2013

Проблема с парсингом JSON, когда встречаются подобные названия в группах - ^it is MerRiLy^

Вот список gid таких групп

27590266
27590308
30731395
40720500
25636833
21162495
6424028
5264005
27593445

https://api.vk.com/method/groups.getById?gids=27590308&fields=members_count

{
"response": [
{
"gid": 27590308,
"name": "^it is MerRiLy^",
"screen_name": "club27590308",
"is_closed": 0,
"type": "page",
"photo": "http://cs9622.vk.me/g27590308/e_5e8febcb.jpg",
"photo_medium": "http://cs9622.vk.me/g27590308/d_f03b4da2.jpg",
"photo_big": "http://cs9622.vk.me/g27590308/a_45b896f7.jpg"
}
]
}

Через гем

@vk.groups.getById(gid: 27590308)


Faraday::Error::ParsingError: Not a valid ID number at line 1, column 54 [load.c:225]

    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-parse_oj-0.1/lib/faraday_middleware/parse_oj.rb:8:in `load'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-parse_oj-0.1/lib/faraday_middleware/parse_oj.rb:8:in `block in <class:ParseOj>'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:48:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:48:in `parse'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:39:in `process_response'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:32:in `block in call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:63:in `on_complete'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:30:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:8:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/response.rb:8:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/vkontakte_api-1.1/lib/vkontakte_api/logger.rb:21:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/request/url_encoded.rb:14:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/request/multipart.rb:13:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday_middleware-0.9.0/lib/faraday_middleware/request/oauth2.rb:40:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/connection.rb:247:in `run_request'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/faraday-0.8.6/lib/faraday/connection.rb:112:in `post'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/vkontakte_api-1.1/lib/vkontakte_api/api.rb:17:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/vkontakte_api-1.1/lib/vkontakte_api/method.rb:13:in `call'
    from /Users/x/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/vkontakte_api-1.1/lib/vkontakte_api/resolver.rb:16:in `method_missing'
    from (irb):22
    from /Users/x/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'irb(main):023:0>

@ghost
Copy link

ghost commented Mar 5, 2013

@targence попробуй удалить "мусор" через нормализацию utf lostisland/faraday_middleware#57

@7even
Copy link
Owner

7even commented Mar 5, 2013

@targence неожиданно. Смогу посмотреть только вечером.
@Zinenko после такой нормализации "неправильные" символы совсем пропадут, или же заменятся на валидные аналоги?

@ghost
Copy link

ghost commented Mar 5, 2013

с невидимыми символами, от которых Oj так же падает, поступает по-разному … чаще всего превращаются в кучи пробелов, которые gsub ом удалются

@7even
Copy link
Owner

7even commented Mar 5, 2013

Дело было совсем не в невидимых символах, а в сериализации, которую по умолчанию делает Oj при генерации JSON - соответственно, при парсинге происходит десериализация. Последовательность ^i при этом имеет особое значение, это и было причиной.

Починилось в 7even/faraday_middleware-parse_oj@9048330. Достаточно обновить faraday_middleware-parse_oj до версии 0.2.

@7even 7even closed this as completed Mar 5, 2013
@targence
Copy link
Contributor Author

targence commented Mar 5, 2013

@7even Спасибо огромное! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants