0

I have a string and need to extract the device_id. In the example I would need "00:06:66:7C:6A:C0"

{   "app_data_quota":{"max":153600,"used":9432},
    "aux_device_data_reference":{"reference_id":70},
    "aux_device_data_in":{"device_id":"00:06:66:7C:6A:C0","aux_data":"LS0tCiQkJA=="},
    "aux_device_data_quota":{"max":153600,"used":9432}
}
3
  • 1
    h.values.select{ |x| x[:device_id] }[0][:device_id] ? Commented Aug 31, 2016 at 6:15
  • Thanks @kiddorails, do you first convert into a Hash? How would you convert this string into a Hash? Commented Sep 1, 2016 at 5:06
  • h = eval(string) Commented Sep 1, 2016 at 5:34

1 Answer 1

1

Lut.

You can save your data in a Hash and then extract the 'device_id' doing something like this:

device_data = {   "app_data_quota":{"max":153600,"used":9432},
    "aux_device_data_reference":{"reference_id":70},
    "aux_device_data_in":{"device_id":"00:06:66:7C:6A:C0","aux_data":"LS0tCiQkJA=="},
    "aux_device_data_quota":{"max":153600,"used":9432}
}
device_id = device_data[:aux_device_data_in][:device_id]

Regards

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Carlos, how can you convert this string into a Hash? I dont find a straightforward solution.
device_data = eval(your_string)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.