【问题标题】:Fetching values from JSON - Clojure从 JSON 中获取值 - Clojure
【发布时间】:2015-07-26 11:33:59
【问题描述】:

如何在 Clojure 中获取 id 的值?我正在使用 clj-json。

{
"response": {
    "users": [
        {
            "id": "5",
            "state": 0
        }
    ]

}
}

【问题讨论】:

    标签: json clojure


    【解决方案1】:

    我在这里假设输入 JSON 在一个名为 input 的字符串变量中:

    (require '(clj-json [core :as json]))
    (-> (json/parse-string input) (get-in ["response" "users"]) first (get "id"))
    
    => "5"
    

    【讨论】:

    • 如果"users"下的值是vector你也可以(get-in json ["response" "users" 0 "id"])
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2013-08-09
    • 1970-01-01
    • 2017-10-22
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多