2012-04-12 53 views
0

我創建LinkedIn這樣的客戶端。如何將LinkedIn客戶端的rails轉換爲哈希

client = LinkedIn::Client.new("3333", "rrrrrrr") 
    client.authorize_from_access(session[:atoken], session[:asecret]) 

,並得到這樣的個人資料,這

@profile = client.profile 

當我打印像 「放client.profile」 的個人主頁上,我得到以下出來把

#<LinkedIn::Profile:0x4a77770 @doc=#<Nokogiri::XML::Document:0x253bb64 name="document" children=[#<Nokogiri::XML::Element:0x253b9fc name="pers 
on" children=[#<Nokogiri::XML::Text:0x253b87c "\n ">, #<Nokogiri::XML::Element:0x253b84c name="first-name" children=[#<Nokogiri::XML::Text:0x 
253b684 "Anthony">]>, #<Nokogiri::XML::Text:0x253b5ac "\n ">, #<Nokogiri::XML::Element:0x253b57c name="last-name" children=[#<Nokogiri::XML:: 
Text:0x253b3b4 "Raj S">]>, #<Nokogiri::XML::Text:0x253b2dc "\n ">, #<Nokogiri::XML::Element:0x253b2ac name="headline" children=[#<Nokogiri::X 
ML::Text:0x253b0e4 "Senior Software Engineer at AB Innovative Software Pvt. Ltd">]>, #<Nokogiri::XML::Text:0x253b00c "\n ">, #<Nokogiri::XML: 
:Element:0x253afdc name="site-standard-profile-request" children=[#<Nokogiri::XML::Text:0x253ae14 "\n ">, #<Nokogiri::XML::Element:0x253ade 
4 name="url" children=[#<Nokogiri::XML::Text:0x253ac1c "http://www.linkedin.com/profile?viewProfile=&key=78718913&authToken=XE_V&authType=name 
&trk=api*a178337*s186521*">]>, #<Nokogiri::XML::Text:0x253ab44 "\n ">]>, #<Nokogiri::XML::Text:0x253aa6c "\n">]>]>> 

如何解析這個到一個hasmap或一個字符串?

請幫助我,因爲我是新來的鐵軌。

+0

看到... http://stackoverflow.com/questions/10122342/how-to-convert-nokogiri-object-to- xml-file-in-rails/10122666#10122666 – davidb 2012-04-12 11:31:01

+0

你想在hashmap/string中做什麼? – Phrogz 2012-04-13 15:13:46

回答

0
  1. 轉換配置文件爲xml 2.manipulate與引入nokogiri
2
  1. 獲取引入nokogiri XML文檔

    xml = @profile.instance_variable_get :@doc 
    
  2. 轉換的引入nokogiri XML文檔的哈希:
    https://stackoverflow.com/a/10144623/405017

如果你想以不同的形式爲你哈希值,然後你應該在問題中指定你想要的輸出。 :p有很多方法可以將XML文檔表示爲散列。

相關問題