How to select a JSON element in Ruby

I have a lot of nested data formatted in JSON .

I would like to select one item:

{"data": [{"id": "123456", "from": {"name": "Jason Wade", "id": "654321"}, "message": "Http://www.youtube .com / watch? v = ZfXHAqBRIEk "...

  • How to effectively select for one element, for example, "message"?

  • Is there a simple method to do this? Say convert it to an array or something else?

  • Could you tell me to read JSON parsing?

Thank!

+3
source share
1 answer

Rails, . . Ruby, json.

require 'rubygems'
require 'json'
url = "www.example.com/api?format=json"
response = Net::HTTP.get_response(URI.parse(url))
data = response.body
result = JSON.parse(data)

JSON ruby ​​ , ,

{"data"=>[{"message"=>"http://www.youtube.com/watch?v=ZfXHAqBRIEk", "from"=>{"name"=>"Jason Wade", "id"=>"654321"}, "id"=>"123456"}]}
+3

Source: https://habr.com/ru/post/1794877/


All Articles