我有一个以JSON格式从Rest返回的对象数组,当我调试时,我只看到引用。我已经将do循环添加到我的一个视图中,但我没有对象的任何属性。我需要做些什么,比如转换数组吗?我是ruby的新手,已经搜索并没有发现任何特定的
第一个控制器不是PolicyList
data3 = data2.map { |rd| PolicyList.new(rd["policyNbr"], rd["systemId"], rd["insuredName"], rd["type"], rd["statusCd"], rd["statusDes"], rd["payorZipcode"], rd["lastPaymentDate"], rd['lastPaymentAmount'], rd["pastDueDate"], rd["pastDueAmount"], rd["currentDueDate"], rd["currentDueAmount"], rd["eft"], rd["suspenseAmt"], rd["expireTime"]) }
$policylist =data3
puts data3.inspect
WebView.navigate(url_for(:controller => :PolicyList, :action => :index))
PolicyList控制器 def index
#@policylists = PolicyList.find(:all)
@policylists = $policylist
render :back => '/app'
end
PolicyList index.erb
<ul data-role="listview">
<% @policylists.each do |policylist| %>
<li>
<a href="<%= url_for :action => :show, :id => policylist.policyNbr %>">
<%= policylist.policyNbr %>
</a>
</li>
<% end %>
</ul>
PolicyList类
# The model has already been created by the framework, and extends Rhom::RhomObject
# You can add more methods here
class PolicyList
include Rhom::PropertyBag
attr_accessor :policyNbr, :systemId, :insuredName,
:type, :statusCd, :statusDes, :payorZipcode,
:lastPaymentDate,:lastPaymentAmount,:pastDueDate,
:pastDueAmount,:currentDueDate,:currentDueAmount,:eft,
:suspenseAmt,:expireTime
尝试检查data2变量(在映射之前)
JSON中的数据可能有一个根元素,像这样:
[
{"policy":{
"policyNbr":"1",
"systemId":"2"
}
},
{"policy":{
"policyNbr":"3",
"systemId":"4"
}
}
]