我想轉換一個web服務響應轉換成在我的Rails應用程序對象,我收到了以下JSON:複雜屬性3.2.12
{
"id": 1,
"status": true,
"password": "123",
"userType": {
"description": "description",
"userTypeId": 1
},
"email": "[email protected]"
}
我想要的用戶類型轉換在用戶類型Ruby類屬性是這樣的:
class UserType
attr_accessor :userTypeId, :description
end
我使用的ActiveResource與web服務進行溝通,我試圖用屬性方法轉換USERTYPE JSON屬性爲用戶等級和積分類,但屬性方法不接受複雜類型,只有字符串,整數e et c ...
如何將userType(webservice response)轉換爲UserType Ruby Class?
Rails的3.2.12和Ruby 1.9.3p194
太棒了@和!你的解決方案工作,現在我可以使用UserType類。我看到你使用ActiveSupport而不是ActiveResource,應該使用哪一種?他們之間有什麼區別?我試圖使用ActiveSupport,但我收到一個錯誤。感謝幫助=)! – danilodeveloper 2013-03-12 13:08:26
哎呀..那裏有一個錯字。它實際上是ActiveResource。 – 2013-03-12 21:12:15
np = D tks再次!!! – danilodeveloper 2013-03-15 00:17:24