ruby -检查json数据类型
HashObj={"id"=>"fae6e87e932c29a0c177512151114f22","at"=>2,"app"=>{"id"=>"9d66d9249cc5bd549b0e68b9fedc69a7","paid"=>0,"cat"=>[10505],"storeurl"=>"https=>//itunes.apple.com/cn/app/id902345501?l=zh&mt=8","name"=>"App Name","bundle"=>"yourcompany.com.app","ver"=>"1.2"},"imp"=>[{"id"=>"5cdef32a55397c48b8baeb3cee0c5b5c","bidfloor"=>6000,"instl"=>0,"bidfloorcur"=>"RMB","banner"=>{"w"=>320,"h"=>50,"pos"=>1}}],"device"=>{"os"=>"iOS","model"=>"iPhone5,1","geo"=>{"lon"=>116.4736795,"type"=>1,"lat"=>39.9960702},"osv"=>"7.0.6","js"=>1,"dnt"=>0,"sh"=>1024,"ip"=>"10.23.45.67","s_density"=>2,"connectiontype"=>2,"dpidsha1"=>"7c222fb2927d828af22f592134e8932480637c0d","ua"=>"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_6 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206","carrier"=>"46000","language"=>"zh","make"=>"Apple","sw"=>768},"user"=>{}} level = 0 def each_kv hh hh.keys.each do |key| val = hh[key] if val.class == Hash # puts "||||| val is #{val} " each_kv val end if val.class == Fixnum || val.class == Float || val.class == Array puts "key #{key } ==> #{val} , #{val.class}" end end end each_kv(HashObj)
posted on 2016-10-13 17:20 iokde.com 阅读(2717) 评论(0) 编辑 收藏 举报