简体   繁体   中英

How to read !ruby/object?

I get response from Tinypass Gem below:

-- !ruby/object:Tinypass::Gateway::PagedList 
list: 
- !ruby/object:Tinypass::Gateway::AccessDetails 
  table: 
    :created: 1403203101
    :uid: MHC3D8N6QS
    :tags: []

    :resource_name: Dashboard content
    :rid: dashboard
    :recur: false
    :expires: 1403807901
    :aid: OQhD8dX7RX
    :amount_usd: 0.5
    :currency: USD
    :amount: 0.5
    :id: LlQpHb1XvzUP
    :user_email: visa@gmail.com
- !ruby/object:Tinypass::Gateway::AccessDetails 
  table: 
    :created: 1403082355
    :uid: H5fRXBjZ3A
    :tags: []

    :resource_name: Dashboard content
    :rid: dashboard
    :user_ref: badashah29
    :recur: false
    :expires: 1403687155
    :aid: OQhD8dX7RX
    :amount_usd: 0.99
    :currency: USD
    :amount: 0.99
    :id: ORvo1LjBs4Hk
    :user_email: badashah265@mailcatch.com

Can any one suggest me how to read user_ref, user_email params from this response.

Thanks

Something like this should work:

require 'yaml'

# parse the yaml from the response
list = YAML.load(response)

# do something with the list
list.each {|access_detail| p access_detail }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM