5

我有一个 json 响应,并希望得到这些值:

(cheshire.core/parse-string (:body picList))

{"photoset" {"primary" "8455893107", "total" "1", "pages" 1, "perpage" 500, "page" 1,
"per_page" 500, "photo" [{"id" "8455893107", "secret" "1a3236df06", "server" "8087", 
"farm" 9, "title" "IMG_0137", "isprimary" "1"}], "owner" "93029076@N07", "id" 
"72157632724688181", "ownername" "clojureB5"}, "stat" "ok"}

如何获得不同的值,例如 photoset->primary 或 photoset->photo->id ?我尝试了一些东西,(map #(get % "photoset")...但它不起作用。

谢谢!

4

1 回答 1

11

我认为您正在寻找clojure.core/get-in

(get-in your-parsed-json ["photoset" "primary"]) ;; "8455893107"

(-> (get-in your-parsed-json ["photoset" "photo"])
  first
  (get "id")) ;; "8455893107"

(get-in your-parsed-json ["photoset" "photo" 0 "id"]) ;; "8455893107"
于 2013-02-12T21:57:44.140 回答