【发布时间】:2017-05-05 14:25:54
【问题描述】:
如何将 xml 响应转换为 json 并从中获取特定值。 这是我尝试过的:
response = HTTParty.post 'http://api.ontraport.com/cdata.php',
{:body => {:appid => 'YeBz0j1',:key => 'NqweN80',:reqType => "fetch_sequences" }}
response = Hash.from_xml(response).to_json
render json: (response)
我得到了结果:
{"result":{"sequence":[{"id":"148"},{"id":"211"},"!Kyle OP Test","(SS) AnikSIB - 1 Hour Reminder","(SS) AnikSIB - 5 minutes Reminder","(SS) AnikSIB - Attended After Over"]}}
但是如果我写render json: (response['result']),那么我的输出是错误的,它只是打印result作为输出。我怎样才能使用JSON.pretty_generate进行漂亮的打印。
【问题讨论】:
标签: ruby-on-rails json ruby xml