Hi
I am trying to read about json output , buts its getting little bit of
hard
url = "http://xxxxxxx:111/v1=rebuild"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
puts data =:::::::::::
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
result = JSON.parse(data)
puts result =:::::::::::::: BD51-101182460TOTAL1459071BD51-5276611
Basically,
I want to see, if the output of "result" or "data" has BD51-5 or not
. ( or the search could be, if BD51-11 is there or not )
i know that JSON.parse puts everything as key->value .. but problem is,
I dont know the key of hash...
how can i get what i want to ?
Thanks for your help
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
I want to see, if the output of "result" or "data" has BD51-5
or not
but problem is, I dont know the key of hash...
BD51-5 is the key:
require 'json'
body =<<JSON_DATA
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
JSON_DATA
Hi
I am trying to read about json output , buts its getting little bit of
hard
url = "http://xxxxxxx:111/v1=rebuild"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
puts data =:::::::::::
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
result = JSON.parse(data)
puts result =:::::::::::::: BD51-101182460TOTAL1459071BD51-5276611
puts result.inspect
will make it a lot clearer. You have a Hash there, but Hash#to_s in ruby
1.8.x just concatenates the keys and values which makes it hard to read.
in case you do not know beforehand which exact key to look for,
you could first extract all keys with Hash#keys and then
select from the resulting array of keys those that match:
puts data =:::::::::::
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
result = JSON.parse(data)
puts result =:::::::::::::: BD51-101182460TOTAL1459071BD51-5276611
Basically,
I want to see, if the output of "result" or "data" has BD51-5 or not
. ( or the search could be, if BD51-11 is there or not )
in case you do not know beforehand which exact key to look for,
you could first extract all keys with Hash#keys and then
select from the resulting array of keys those that match:
puts data =:::::::::::
{"BD51-5":276611,"TOTAL":1459071,"BD51-10":1182460}
result = JSON.parse(data)
puts result =:::::::::::::: BD51-101182460TOTAL1459071BD51-5276611
Basically,
I want to see, if the output of "result" or "data" has BD51-5 or not
. ( or the search could be, if BD51-11 is there or not )