Clojure 获取地图中的值
Clojure get the value inside a map
如何在地图中获取 openid.claimed_id 或任何其他字段?
:openid.claimed_id 不行。
{"openid.response_nonce" "2015-07-25T09:31:45ZXrcrR0Lk35St5ESZQ0tg40PbBXU=", "openid.identity" "http://steamcommunity.com/openid/id/xxx", "openid.ns" "http://specs.openid.net/auth/2.0", "openid.op_endpoint" "https://steamcommunity.com/openid/login", "openid.mode" "id_res", "openid.sig" "zuiyNzf/QLP9Ci/czElIo1Z3nE0=", "openid.signed" "signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle", "openid.assoc_handle" "1234567890", "openid.claimed_id" "http://steamcommunity.com/openid/id/xxx", "openid.return_to" "http://localhost:3000/resp"}
地图中的键是字符串而不是关键字。
您可以使用:
(get m "openid.claimed_id")
或者您可以先将字符串键转换为关键字,然后根据关键字查找:
(:openid.claimed_id (clojure.walk/keywordize-keys m))
由于 map 也是一个可以对自身进行查找的函数,因此最简单的方法是
(m "openid.claimed_id")
m
是你的地图。
如何在地图中获取 openid.claimed_id 或任何其他字段?
:openid.claimed_id 不行。
{"openid.response_nonce" "2015-07-25T09:31:45ZXrcrR0Lk35St5ESZQ0tg40PbBXU=", "openid.identity" "http://steamcommunity.com/openid/id/xxx", "openid.ns" "http://specs.openid.net/auth/2.0", "openid.op_endpoint" "https://steamcommunity.com/openid/login", "openid.mode" "id_res", "openid.sig" "zuiyNzf/QLP9Ci/czElIo1Z3nE0=", "openid.signed" "signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle", "openid.assoc_handle" "1234567890", "openid.claimed_id" "http://steamcommunity.com/openid/id/xxx", "openid.return_to" "http://localhost:3000/resp"}
地图中的键是字符串而不是关键字。
您可以使用:
(get m "openid.claimed_id")
或者您可以先将字符串键转换为关键字,然后根据关键字查找:
(:openid.claimed_id (clojure.walk/keywordize-keys m))
由于 map 也是一个可以对自身进行查找的函数,因此最简单的方法是
(m "openid.claimed_id")
m
是你的地图。