1

When in my ruby console, a = first is

=> <Ng::EntityConfiguration id: 15881, entity_id: 1, entity_type: "Ng::Company", key: "wpa2.psk", value: "[{"ssid":"LVL6-Staff","password":"987654321", created_at: "2016-11-08 05:13:04", updated_at: "2016-11-08 05:13:04", name: "WIFI/Level 6">

then a.value

will give you => "[{"ssid":"LVL6-Staff","password":"987654321","dhcp":"Enabled"}]"

My question is, how to get the value when object is Password? because when I try with a.value[:password] got an error.

3
  • Is a.value a hash inside an array, inside a string? I tried to look at the original record and it doesn't match the pulled about value of a.value. Commented Nov 8, 2016 at 6:32
  • first.value also will return to you => "[{"ssid":"LVL6-Staff","password":"987654321","dhcp":"Enabled"}]" From original record, you can see it inside value: "" Commented Nov 8, 2016 at 6:33
  • Copying and pasting the code causes errors. Had to wrap it in single quotes, instead of double, to get the proper string to exist. Then it worked as I expected. Commented Nov 8, 2016 at 6:40

1 Answer 1

2

It is a JSON string, after JSON.parse() is an array with hashes.

>> x = JSON.parse("[{\"ssid\":\"LVL6-Staff\",\"password\":\"987654321\",\"dhcp\":\"Enabled\"}]")
=> [{"ssid"=>"LVL6-Staff", "password"=>"987654321", "dhcp"=>"Enabled"}]
>> x.last['password']
=> "987654321"
Sign up to request clarification or add additional context in comments.

Comments

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.