如何将rails客户端转换为Hash
我像这样创建linkedin客户端。
client = LinkedIn::Client.new("3333", "rrrrrrr") client.authorize_from_access(session[:atoken], session[:asecret])
并获得这样的个人资料信息
@profile = client.profile
当我打印像“ puts client.profile ”这样的配置文件时,我得到以下输出
#<LinkedIn::Profile:0x4a77770 @doc=#<Nokogiri::XML::Document:0x253bb64 name="document" children=[#<Nokogiri::XML::Element:0x253b9fc name="pers on" children=[#, #<Nokogiri::XML::Element:0x253b84c name="first-name" children=[#]>, #, #<Nokogiri::XML::Element:0x253b57c name="last-name" children=[#]>, #, #<Nokogiri::XML::Element:0x253b2ac name="headline" children=[#]>, #, #<Nokogiri::XML: :Element:0x253afdc name="site-standard-profile-request" children=[#, #<Nokogiri::XML::Element:0x253ade 4 name="url" children=[#]>, #]>, #]>]>>
如何将其解析为hasmap或字符串?
请求帮助我,因为我是铁杆新手。
-
获取Nokogiri XML文档
xml = @profile.instance_variable_get :@doc
-
将Nokogiri XML文档转换为哈希:
https://stackoverflow.com/a/10144623/405017
如果你想要一个不同的表格哈希,那么你应该在问题中指定你想要的输出。 :p有很多种方法可以将XML文档表示为哈希。
- 使用nokogiri将配置文件转换为xml 2.manipulate