我努力了:
require 'net/http'
require 'json'
require 'pp'
require 'uri'
url = "http://xyz.com"
resp = Net::HTTP.get_response(URI.parse(url))
buffer = resp.body
result = JSON.parse(buffer)
#result.to_hash
#pp result
puts result
并得到输出:
{"id"=>"ABC", "account_id"=>"123", "first_name"=> "PEUS" }
采用 JSON 格式,但我只需id
要将 的值打印为ABC
.