文章是从我的个人博客上粘贴过来的,
大家也可以访问 www.iwangzheng.com
url点开后的json是这样的
{
- e:
{
- provider: ”searches.soku.top”,
- code: 0,
- desc: ”OK”
},
- total: 1320,
- cost: 35,
- data:
[
-
{
- promId: 278579,
- queryCount: 69799,
- keyword: "熊出没"
},
- {
- promId: 110787,
- queryCount: 12579,
- keyword: "倒霉熊"
},
- {
- promId: 253153,
- queryCount: 11341,
- keyword: "天线宝宝"
},
- {
- promId: 217505,
- queryCount: 11095,
- keyword: "网球王子"
}
]
-
}
JSON.parse(HTTParty.get(url).body)["data"]
[{"promId"=>278579, "queryCount"=>69799, "cateId"=>5, "keyword"=>"熊出没"},
{"promId"=>284119, "queryCount"=>67475, "cateId"=>5, "keyword"=>"啦啦啦德玛西亚"},
{"promId"=>276009, "queryCount"=>14648, "cateId"=>5, "keyword"=>"变形金刚"},
{"promId"=>110787, "queryCount"=>12579, "cateId"=>5, "keyword"=>"倒霉熊"}]
JSON.parse(HTTParty.get(url).body)["data"].map{|hash| hash["promId"]}
得到的就是
[278579, 284119, 19461]