开发者

Finding uid from a hash not working

开发者 https://www.devze.com 2023-03-24 21:22 出处:网络
I have a JSON response from Facebook liking like this. [ {\"uid\"=>123, \"name\"=>\"Test\", \"is_app_user\"=>true},

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"]
0

精彩评论

暂无评论...
验证码 换一张
取 消