我在循环中解析json数据时遇到问题。我是一个clojure初学者,需要一些提示来循环json数据。
数据如下所示:
{"photoset" {"primary" "8455893107", "total" "2", "pages" 1, "perpage" 500, "page" 1,
"per_page" 500, "photo"
[{"id" "8455893107", "secret" "1a3236df06", "server" "8087",
"farm" 9, "title" "IMG_0137", "isprimary" "1"}
{"id" "8469482476", "secret" "4c1bf59214",
"server" "8235", "farm" 9, "title" "HippieBus", "isprimary" "0"}]
, "owner"
"93029076@N07", "id" "72157632724688181", "ownername" "clojureB5"}, "stat" "ok"}
我想要做的是循环显示两张照片并构建一个ID为http://www.flickr.com/farm/id
的ID和值为新的网址我知道我可以得到一个这样的值:
(-> (get-in (cheshire.core/parse-string (:body picList)) ["photoset" "photo"]) first (get "id"))
但我现在可以循环播放吗?
答案 0 :(得分:4)
您只需使用map
。
(->> (get-in data ["photoset" "photo"])
(map #(str "http://www.flickr.com/" (get % "farm") "/" (get % "id"))))
它将产生以下列表:
(“http://www.flickr.com/9/8455893107”“http://www.flickr.com/9/8469482476”)