ruby解析json、xml
2016-07-25 13:34
429 查看
ruby解析json、xml
解析xml[ruby] view
plain copy
def get_xml_element(url,xml_element)
require 'net/http'
response=Net::HTTP.get_response(URI('http://api.platform.com/cinema/halls/format/xml/cid/1/pid/10000'))
#~ puts response.code
s = response.body
#~ puts s
s.scan(/\<#{xml_element}\>(.*)\<\/#{xml_element}\>/)
end
url='http://api.platform.com/cinema/halls/format/xml/cid/1/pid/10000'
puts get_xml_element(url,'errorMessage')
解析json
[ruby] view
plain copy
require 'net\http'
require 'json'
response=Net::HTTP.get_response(URI('http://api.platform.com/cinema/halls/format/json/cid/1/pid/10000'))
puts response.body
data=response.body
result=JSON.parse(data)
p result
puts result['res']['errorMessage']
相关文章推荐
- Mac上更新Ruby
- ruby on rails 常用的日期取值
- ruby on rails (MVC)
- RubyGems 镜像
- ruby的redo和retry 回顾
- 24点计算器Ruby脚本
- iOS Mac系统下Ruby环境安装
- 编译安装Ruby2.3.1
- 研发支撑系统ruby on rails环境
- ruby 中的sort 和 sort_by
- Ruby gem: Mac 系统下的安装与更新
- 如何在Mac OS X上安装 Ruby运行环境
- cocoapods安装
- 如何在Mac下正常的安装Ruby环境
- [Ruby笔记]28.Ruby @@class_variables 类变量 vs @instance_variable 实例变量
- ruby爬虫日记1
- ruby安装redmine插件
- ruby学习之-------问题整理
- “Accept-Encoding: gzip, deflate”问题
- cocoapods使用