有没有人成功使用过这个接口?尝试构建价格比较功能,但在将json数据解析为rails数据结构时遇到了问题。我试图过滤的结果,只卖家和最新报价。有人有解决方案吗?
我的控制器
sem3.products_field("search", "green toys tractor")
sem3.products_field( "sitedetails", "name")
# Make the query
@productsHash = sem3.get_products()在视图中
<%= @productsHash %>我能够看到整个json散列,并且我尝试用json gem解析它。
JSON.parse(@productsHash)但是想知道是否有人有自己的示例代码可以分享。
我的结果
{"total_results_count"=>9189,"code"=>"OK","offset"=>0,"results_count"=>10,"results"=>[{"cat_id"=>"20823","ean"=>"0649241988953","model"=>"UMB13 A1342 GREEN","offers_total"=>19,"weight"=>"340194.28",“category”=>“笔记本电脑和上网本附件”,“name”=>“绿色mCover®硬壳外壳外壳+ A1342白色一体机的免费键盘外壳13英寸”,"updated_at"=>1387963145,"width"=>"335.28","upc"=>"649241988953",“brand”=>“绿色”,"created_at"=>1347717401,“color”=>“绿色”,“sem3_id”=>“1jAjbOWu XQmWG0wMwGg46m”,“features”=>{“产品尺寸”=>“9.2 x 13.2 x 1.1英寸;12盎司“},”高度“=>”27.94“,”长度“=>”233.68“,”制造商“=>”iPearl Inc.,美国“,"gtins"=>"00649241988953",”geo“=>”美国“,"price_currency"=>"USD",”价格“=>”17.80“,”sem3_help“=>”要查看此产品的图像链接和其他商家,请升级您的计划。“},{"cat_id"=>"20823","ean"=>"0649241988403",型号=>offers_total MB绿色,=>25,重量=>285763.19,类别=>笔记本电脑和上网本电脑配件,名称=>绿色mCover硬壳外壳13英寸铝A1278 MacBook MacBook(13.3英寸对角线屏幕),updated_at=>1387817680,价格=>13.99,宽度=>28.45,=>649241988403,品牌=>绿色,created_at=>1347554377,"sem3_id"=>"6VQYSLooueo2ks0WUqIec2",“features”=>{“产品尺寸”=>“13 x 1.1 x 9.1英寸;10.1盎司“},"mpn"=>"ALU-MB-GREEN","height"=>"231.65","length"=>"330.20","manufacturer"=>"iPearl Inc.,USA","gtins"=>"00649241988403","geo"=>"usa","price_currency"=>"USD",”sem3_help“=>”要查看此产品的图像链接和其他商家,请升级您的计划。“},{"cat_id"=>"20823","ean"=>"0872621001632",型号=>RT SPM14X02,offers_total=>509,重量=>158757.33,类别=>笔记本电脑和上网本电脑配件,名称=>青葱供应RT-SPM14X02戴尔Alienware M14x的防眩光屏幕保护器,updated_at=>1388313241,价格=>28.87,=>872621001632,品牌=>绿色,sem3_id=>2c8IsQrCnMq8KgEgiMo6yW,created_at=>1347808883,“Feature”=>{“Package Content"=>"MicroFiber cloth","Display screen Size Compatibility"=>"14\”wide",“其他功能”=>“防眩,防刮,可重复使用”,"Product Type“=>”笔记本屏幕保护器“},"mpn"=>"RT-SPM14X02","sitedetails"=>[{"sku"=>"17046069",”latestoffers“=>{”“卖方”“=>”沃尔玛“,"lastrecorded_at"=>1387704200,"firstrecorded_at"=>1379990800,"currency"=>"USD",“可用性”=>“现货”,“价格”=>“32.24”,"id"=>"5pPydRLcRcUIIeu8iG4o4K"},{“卖方”=>“沃尔玛”,"lastrecorded_at"=>1360662000,"firstrecorded_at"=>1360662000,"currency"=>"USD",“availability”=>“现货”,"id"=>"7Yf1biLaZkMcSwOyKUuS4m","price"=>"31.24"},{“卖方”=>“沃尔玛”,"lastrecorded_at"=>1358731800,"firstrecorded_at"=>1358731800,“货币”=>“USD”,“=>”现货“,"id"=>"51zIYD0tYeSECu4KGuKC2s",”=>“30.93”},"name"=>"walmart.com","offers_count"=>20,"url"=>"http://www.walmart.com/ip/17046069","recentoffers_count"=>1},{"offers_count"=>3,"sku"=>"1092214",zzIYD0tYeSECu4KGuKC2s“,”=>“=>”USD“,”firstrecorded_at“,“可用性”=>“可用”,"id"=>"0QuY3kcCdagYaUeGwYyS2o",“价格”=>“35.95”},{“卖方”=>“NextWarehouse.com”,"lastrecorded_at"=>1382359600,“货币”=>“USD”,"firstrecorded_at"=>1382359600,“可用性”=>“可用”,“价格”=>“36.13”,“id”=>“2SLtd 8pdveGqGUaAWW0w62”},{“卖方”=>“NextWarehouse.com”,"lastrecorded_at"=>1379825800,"firstrecorded_at"=>1379825800,"currency"=>"USD","availability"=>"Available",“id”=>“7eJC9XXVuQ8GWSqWCIqKq”,“=>”35.95“},"url"=>"http://www.nextwarehouse.com/item/?1092214_g10e","name"=>"nextwarehouse.com","recentoffers_count"=>1},{"offers_count"=>3,"sku"=>"1604730",”latestoffers“=>{”卖方“=>”Colamco“,"lastrecorded_at"=>1384661400,"currency"=>"USD",”firstrecorded_at“,“可用性”=>“可用”,"id"=>"1ZNuX5bmpY4mACsIOqIg8K",“=>”36.27“},{”卖方“=>”Colamco“,"lastrecorded_at"=>1382359600,”货币“=>”USD“,"firstrecorded_at"=>1382359600,”可用性“=>”,“价格”=>“36.60”,“id”=>“39GVaekhIuOyAeyOyKkCc”},{“卖方”=>“Colamco”,"lastrecorded_at"=>1379825800,"firstrecorded_at"=>1379825800,“货币”=>“USD”,“可用性”价格“可用”,"id"=>"05CmUv60bxIQiumM0mWgUe",“=>”=>“34.27”}
发布于 2015-03-27 18:33:42
只需循环@productshash,因为它是一个散列数组,并使用您希望获得与其关联的值的特定键
在您的rails控制器中,只需使用以下代码
sem3.products_field("search", "green toys tractor")
sem3.products_field( "sitedetails", "name")
# Make the query
productsHash = sem3.get_products()
@products = productsHash["results"]在视图中,只需循环@product
<% @products.each do |prod| %>
<%= "Product name: #{prod["name"]}"%>
#You can use as many as fields you want
<%end%>https://stackoverflow.com/questions/20861291
复制相似问题