Ruby为什么无法解析此(主目录)JSON数据?

时间:2019-06-30 18:07:40

标签: ruby api parsing facebook-graph-api httparty

我无法在json返回的主目录中打印值。

我想循环返回以下字段

require 'httparty'
require 'rubygems'

response = HTTParty.get("https://www.instagram.com/p/BvNWyEpDoz2/?__a=1")


response['graphql']['shortcode_media'].each do |child|

    puts child['__typename']

    puts child['id']

    puts child['display_url']

    puts child['edge_media_to_parent_comment']['edges']

    puts child['node']['text']

end
Traceback (most recent call last):
    2: from apisample2.rb:7:in `<main>'
    1: from apisample2.rb:7:in `each'
apisample2.rb:9:in `block in <main>': undefined method `[]' for nil:NilClass (NoMethodError)


Traceback (most recent call last):
    3: from apisample2.rb:7:in `<main>'
    2: from apisample2.rb:7:in `each'
    1: from apisample2.rb:9:in `block in <main>'
apisample2.rb:9:in `[]': no implicit conversion of String into Integer (TypeError)

0 个答案:

没有答案