2

我在循环中解析 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 和农场值构建一个新的 url,如http://www.flickr.com/farm/id

我知道我可以得到这样的一个值:

(-> (get-in (cheshire.core/parse-string (:body picList)) ["photoset" "photo"]) first (get "id"))

但是我现在可以循环遍历它吗?

4

1 回答 1

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

于 2013-02-13T14:38:49.860 回答