Finding uid from a hash not working
I have a JSON response from Facebook liking like this.
[
{"uid"=>123, "name"=>"Test", "is_app_user"=>true},
{"uid"=>1234, "name"=>"Test1", "is_app_user"=>true}
]
I save this result to @test and then:
@test.select {|k,v| k == "name"}}
But the result is an empty array instead of the desired result:
[]
Desired output (1)
[{"name" => "Test"}, { "name" => "Test1"}]
and then (2)
[Test, Test1] * This will be used to query the datab开发者_运维百科ase
Any suggestions? Thanks.
@test = [
{"uid"=>123, "name"=>"Test", "is_app_user"=>true},
{"uid"=>1234, "name"=>"Test1", "is_app_user"=>true}
]
@test.collect { |itm| itm["name"] }
=> ["Test", "Test1"]
精彩评论