Parsear 2 jsonArray in Ruby

0

I have this little problem in Ruby, I have an api with this response:

response: [
  {
    waspurchase: 1,
    purchase_data: {
      gateway: "plazavipgate",
      gateway_text: "TEXT_PGS_PAYMENT_ASD_ASD_ASD",
      gateway_data: {
        card_owner_name: "PEPITO",
        card_type: "2",
        card_number_display: "XXXX XXXX XXXX 1234",
        address: "ASDSDADSD",
        city: "ASDASDSADSA",
        state: "ASDASDSAD",
        expiration_month: "1",
        expiration_year: "123",
        birth_date: "",
        phone_number: "5555555555",
        zip_code: "1234"
      },
      beggining: "17/07/2017 10:29:51",
      expiration: "17/08/2017 10:29:51",
      expiration_promo: "17/08/2017 10:29:51",
      in_process_canceled: 0,
      purchase_id: "12321414"
    },
    offer_id: "123457",
    user_id: 12345623,
    price: "17/07/2017 10:29:51",
    currency: "$",
    offer_text: "TEXT_PGS_OFFER_ASD_ASD_SVOD_30D"
  },
  {
    waspurchase: 0,
    purchase_data: "",
    offer_id: "1234567",
    user_id: 1234567,
    price: "123",
    currency: "$",
    offer_text: "TEXT_PGS_OFFER_ASD_ABONO_ASD"
  }
]

And I need to parse from the first data list the field card_owner_name , the problem is that when pairing is lost since within the response there are repeated fields.

    
asked by Nicolas 17.07.2017 в 18:18
source

1 answer

0

To obtain data from the first list, you only have to refer to it according to its position in the array, that is, using [0] ; for example, considering that the response obtained saves it in a variable resultado :

resultado = response: [{ ... }]

So, to get the value of card_owner_name you could do it like this:

resultado[:response][0][:purchase_data][:gateway_data][:card_owner_name]
#=> "PEPITO"
    
answered by 17.07.2017 / 19:36
source