json && happarty

require 'json'
require 'httparty'

When /^接口返回<(.+)><(.+)>$/ do |url_yaml_name,url_condition_yaml_name|

    url = @url[url_yaml_name][0]
    url_condition = @url_condition[url_condition_yaml_name][0]
    real_value = url_condition.split(",")
     (0..real_value.size-1).each do|i|
        url = url.sub('*',real_value[i])
      end
    puts url
uri = URI.encode(url)
    cookie = "vendor_id=89"
response = HTTParty.get(uri, :headers=> {'Cookie' => cookie})
puts response.body
a = JSON.parse response.body
   results = {}
   size = a["multipleResult"].length - 1
   for i in 0..size
      num = a["multipleResult"][i].keys().size
      
      for j in 0..num
        results[a["multipleResult"][i].keys()[j]] ||= Array.new
        #注意使用<<,如何使用的是=,将会被代替
        results[a["multipleResult"][i].keys()[j]] << a["multipleResult"][i].values()[j]
      end
   end 
   @api_results = results
end

你可能感兴趣的:(json && happarty)